mem0ri Posted March 13, 2008 Share Posted March 13, 2008 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 More sharing options...
Stooney Posted March 13, 2008 Share Posted March 13, 2008 I believe you need the parenthesis when creating a new object: (I could be wrong) $data = new ReceiveComms(); Link to comment https://forums.phpfreaks.com/topic/96027-__get-function-failingunknown-reason/#findComment-491629 Share on other sites More sharing options...
keeB Posted March 13, 2008 Share Posted March 13, 2008 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 https://forums.phpfreaks.com/topic/96027-__get-function-failingunknown-reason/#findComment-491657 Share on other sites More sharing options...
mem0ri Posted March 14, 2008 Author Share Posted March 14, 2008 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 https://forums.phpfreaks.com/topic/96027-__get-function-failingunknown-reason/#findComment-491858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.