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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 2 weeks later...
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.