Jump to content

[SOLVED] Strange error - Works with XAMPP


phant0m

Recommended Posts

Hello

 

I've got this strange error...

Fatal error: Cannot use object of type User as array in ...

I don't get this with XAMPP(PHP 5.2.5) but I get it on my remote host(PHP5.2.6)

 

What I do?

 

Well, bascially, I've got this class called "User" and it's got some attribute which is an array. At the end(__destruct) I put it in the session

$_SESSION['user'] = $this->user

 

When an instance is created, it checks whether $_SESSION['user'] is set.

If it isn't the field is initialized with an empty array in order to be stored into the session at the end.

If it is set however, I first assign it to $this->user and then check whether a certain element is empty. This is where the error is triggered.

if(isset($_SESSION['user'])){
        /* some other code here */
        $this->user = $_SESSION['user']; //this is the only place where something is assigned to $this->user
        if(!empty($this->user['name'])){

It seems as if online, $this->user is a reference to $this, which is really weird.

How can it be, that $this->user is a reference to $this on my remote server, yet on my local installation works flawlessly.

 

Also, I used var_dump online to check what $this->user contains immediately before it is assigned to $_SESSION['user']. It contains exactly what I wanted it to: An array with a little information.

 

Something else I've noticed: All the arrays stored in $_SESSION seem to be a reference online:

&array(2){...}

But "offline", it's like this:

array(2){...}

 

 

Of course, this error doesn't appear when you access the page the first time, because by that time the session is empty and the array is initialized with default values.

Any ideas? Thanks in advance.

Link to comment
Share on other sites

But I don't want to store the object in the session ;)

 

I wanted it to contain an array, but for some strange reasons, the next time I check the array is gone and an object is there. - But on XAMPP - it doesn't happen. No object whatsoever, the array is always there.  ???

Link to comment
Share on other sites

Ok, I have uploaded my site to a different server(Same hosting company)

Results:

===Server #1(Remote)

Running: PHP 5.2.6

Errors: Fatal Error upon 2nd request due to some SESSION problem, explained above

 

===Server #2(Remote)

Running: PHP 5.2.6

Errors: None - Everything works flawlessly

 

===Server #3(localhost)

Running: PHP 5.2.5

Errors: None - Everything works flawlessly

Link to comment
Share on other sites

Thanks for the input but it doesn't help.

The error still occurs.

!is_object($this->user) is always validated true, so $this->user is always assigned to $_SESSION['user'].

 

I have searched my entire project to find occurrences of $_SESSION['user']

There are 3. And only in one of these occurrences, something is being assigned to it: $_SESSION['user'] = $this->user;

 

As I had already tested before, $this->user never contains an object when trying to assign it to $_SESSION['users']

But inexplicably, $_SESSION['user'] contains an object when I resume the session on a 2nd request.

 

This is driving me crazy...

 

//edit: Another idea I've had(which was rather unlikely though): Perhaps I assigned something directly to $_SESSION... namely an array containing a key called 'user' which was a reference to that object. I searched for: SESSION\s*= - but it did not return any results

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.