denniss
denniss

Reputation: 17589

OOP PHP Weird undefined method

Can someone tell me why I am getting undefined method print_hash() error?

I have the following class

    class EmailManager{
 private $replytoArray;
 private $receiverArray;
 private $fromArray;

 function __construct(){
  $replytoArray = array();
  $receiverArray = array();
  $fromArray = array();
 }
 function addReceiver($k){
  if(!in_array($k, $receiverArray)){
   $receiverArray[] = $k;
   return true;
  }
  return false;
 }
 function addReplyTo($k){
  if(!in_array($k, $replytoArray)){
   $replytoArray[] = $k;
   return true;
  }
  return false;
 }
 function debug(){
  print_hash($replytoArray);
  print_hash($receiverArray);
 }
 function print_hash($k){
  echo "<pre>";
  print_r($k);
  echo "</pre></br>";
 }
}

And I want to make sure everything is fine so I tried to test it

    <?php
 error_reporting(E_ALL);
 ini_set("display_errors",1);
 require_once("EmailManager.php");

 $em = new EmailManager();
 $em->debug();
 //$em->addReceiver("[email protected]");
?>

Upvotes: 1

Views: 121

Answers (3)

wodka
wodka

Reputation: 1380

You have to call $this->print_hash(...) it is only available inside your object.

Upvotes: 1

Mewp
Mewp

Reputation: 4715

print_hash() is a class method, so you need to use $this->print_hash().

Upvotes: 1

fabrik
fabrik

Reputation: 14365

You need to use $this->print_hash() inside of debug().

Upvotes: 3

Related Questions