/    Sign up×
Community /Pin to ProfileBookmark

Ok so I’ve been developing a page using php5.1.16. My webhost is using 5.2.0.

However, this code works fine with my personal testing server:

[code=php]
$page[“content”][0][“title”] = ‘title’;
$page[“content”][0][“subtitle”] = ‘sub sub’;
$page[“content”][0][“content”] = ‘text text text’;[/code]

But it returns this error on my web host:

[code=php]Fatal error: Cannot use string offset as an array in /usr/home/user/public_html/site/code.php on line n[/code]

Where n is the first line in the example code above.

Have I been using arrays wrong all along?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisDec 12.2006 — Try changing the double-quotes to single-quotes to see if that "fixes" the problem.

Perhaps that version of PHP has added some new reserved words.
Copy linkTweet thisAlerts:
@NogDogDec 12.2006 — I think that indicates that $page has already been set somewhere else in the code as a string. Is it possible that the host where the problem is occurring has register_globals enabled and that you have a superglobal value such as $_GET['page'] or $_SESSION['page'] which is therefore also creating the variable $page from the register_globals functionality? If so, the simple fix would be to add the following before you start assigning values to the array:
[code=php]
$page = array();
[/code]
Copy linkTweet thisAlerts:
@DraikeauthorDec 12.2006 — Yes! Yes I do have a superglobal $_GET['page']. I'm not sure if register_globals is on though. But I'll change the $page to $pages or something and see if that works.

Thanks
Copy linkTweet thisAlerts:
@DraikeauthorDec 12.2006 — Update: Sweetness NogDog! Worked like a charm. I just changed the variable name and it worked again just like that. *snap*.

So problem fixed. ?
×

Success!

Help @Draike spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...