Jump to content

variable isn't getting passed along.


Bramme

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/79606-variable-isnt-getting-passed-along/
Share on other sites

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.

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();

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!

  • 2 weeks later...

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.