4

I'm trying to debug a class that I made. It always breaks and throw undefined variable on the logs I couldn't find a solution because I don't know what I'm doing wrong, I think it should work but not.

The undefined variable is on the erase() function, not in the show() function

class pepe{
 private $array = array();

 function show(){
   $this->erase();
   print_r($this->array);
 }
 function erase(){
   print_r($this->array); 
 }
}

$o = new pepe();
$s = $o->show();
3
  • it works to me: $s = $o->erase(); Commented May 21, 2015 at 5:27
  • It should work, i posted a simple example, in my code isnt working pastebin.com/PsTXeJ6D On line 110 it says undefined variable Commented May 21, 2015 at 5:37
  • Found the error made by me, it's not good to work at 3am. In my code i have $o->$array(); Thanks a lot people! Commented May 21, 2015 at 5:53

1 Answer 1

2
class pepe{

private $array = array();

 

function show(){

$this->erase();

print_r($this->array);

}

function erase(){

print_r($this->array); 

}

}

 

$o = new pepe();

$s = pepe->show();

Why are you calling pepe here? Should be like this:

  class pepe{
    private $array = array();

 function show(){
   $this->erase();
   print_r($this->array);
 }
 function erase(){
   print_r($this->array); 
 }
}

$o = new pepe();
$s = $o->show();

You have to call

$o->show()

because you've assigned pepe to

$o
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.