php - Multiple return from a class function -


i learning php oop. while writing class getting logical problem function not returning more 1 value , getting default value output. when pass 2 variables in function setproperty() , call getproperty(), returns author's name. here code:

class library{     public $bookname="php oop programming";     public $author="faisal";      public function setproperty($a_name,$b_name){         $this->author=$a_name;         //$this->bookname=$b_name;     }      public function getproperty(){         return $this->author."<br />";         //return $this->bookname."<br />";     } } $obj=new library; //var_dump($obj);  echo $obj->getproperty(); $obj->setproperty("naseer","sql"); echo $obj->getproperty(); 

and i'm getting output:

faisal naseer 

whereas output wanted author's name along books, like:

faisal php oop programming  naseer sql 

you cannot return multiple times in function.

if need return more 1 value can like:

return array('author'=>$this->author, 'bookname'=>$this->bookname); 

and use this:

$res = $obj->getproperty(); echo "author ".$res['author']; echo "book ".$res['bookname']; 

you may want change depending on method for/ how used.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -