Bramme Posted November 30, 2007 Share Posted November 30, 2007 Example of what's happening: class MyClass { private $items = array(); function dostuffwithitems() { do stuff; return $this->items; } function dosmthelse() { print_r($this->items); } } I did the print_r to test because my second function wasn't working, and it just echo'ed array( )... It's still empty, if I change the private var to 'boo', it prints 'boo' instead of the array I built with the first function... I've tried it with other variables too, nothing prints correctly or returns like it should... Anyone can tell me what I'm doing wrong? Full code here: http://dev.bramme.net/files/Modular.class.phps Quote Link to comment Share on other sites More sharing options...
Bramme Posted December 1, 2007 Author Share Posted December 1, 2007 I don't need a line specific correction here, I just need some pointers to know where to look at... Did I probably forget to mention a $this-> somewhere, could it be a typo or is it some php setting... I'm completely at a loss here, I don't know where to look at. Quote Link to comment Share on other sites More sharing options...
eddedwards Posted December 4, 2007 Share Posted December 4, 2007 How are you calling the function? $test = new myclass(); $test->dostuffwithitems(); // this wouldnt work i dont think as your returning an array to nowhere. I think you need to change the function a little. maybee a little like this. function dostuffwithitems() { $stuff = array('asdf','iuayhdiufayhi','yy4nehdu'); $this->items = $stuff; // <------ return true; } or call your function into a variable. $myclass->items = $myclass->dostuffwithitems(); Quote Link to comment Share on other sites More sharing options...
Bramme Posted December 4, 2007 Author Share Posted December 4, 2007 hmm, i totally forgot about htis topic. the problem has been solved... I rewrote a part of the class indeed, but also changed the order of which fucntions i'm calling in index.php, i think the problem might've been there.... dunno for sure though. Anyway, it's solved. thanks for the info though! Quote Link to comment Share on other sites More sharing options...
xinteractx Posted December 18, 2007 Share Posted December 18, 2007 I don't think you should output to the browser with any type of print statement directly from the object. I think you should returned the result to your application then have your application output to browser Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.