Jump to content

__get function failing...unknown reason...


mem0ri

Recommended Posts

Server: PHP 5.2.0

 

Class runs without error.

Page runs without error.

 

When I try to reference -any- variable acquired through the __get function, however, the page fails and load stops.

 

reference in page:

$data = new ReceiveComms; //takes $_GET and $_POST and $_HEADER variables and places them in arrays.

echo $data->obj;

 

Class function:


public function __get($property)
{
	if(array_key_exists($property, $this->headers)) return $this->headers($property);
	else if(array_key_exists($property, $this->data)) return $this->data($property);
	else return NULL;
}

 

Interesting thing is...if I print_r either $this->headers or $this->data, they have all of the appropriate values...and $this->data has the 'obj' key...

 

...anyone else experience similar problems?  Any solutions?

Link to comment
Share on other sites

I believe you need the parenthesis when creating a new object:  (I could be wrong)

$data = new ReceiveComms();

 

You are wrong. :)

 

 

To the op: You didn't provide much data.

 

__get is not something I work with, though. It's being extremely lazy. Opening up your entire for get/set is bound to cause way too much of a headache down the line.

Link to comment
Share on other sites

Thanks to both posters...

 

...no, a new object does not need parentheses...

 

...I also agree that opening up an entire __get and __set can be messy...but I did so on this class because it exists purely for the purpose of taking received variables, manipulating them, and then placing them into the only class-global variables that exist for the express purpose of getting and setting those array values within the page.

 

The problem was actually...

if(array_key_exists($property, $this->headers)) return $this->headers($property);

 

needed to be

if(array_key_exists($property, $this->headers)) return $this->headers[$property];

 

Talk about a headache over nothing...just found that after leaving the project and coming back and scratching my head a bit.

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.