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
https://forums.phpfreaks.com/topic/96027-__get-function-failingunknown-reason/
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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.