php - Returning and Echoing multiple variables -
i've written following php script intended echo 3 variables captured in constructor book
within class book
.
i'd php echo 3 variables. however, @ moment echoes 1 of three.
here code:
<?php class book { protected $title; protected $author; protected $yearpublished; function book($title, $author, $yearpublished) { $this->title=$title; $this->author=$author; $this->yearpublished=$yearpublished; } function summary() { return $this->title; return $this->author; return $this->yearpublished; sprintf($this->title, $this->author, $this->yearpublished); } } $test= new book("pride , prejudice","john doe","2016"); $test->summary(); echo $test->summary();
you have change function to
function summary(){ return $this->title; return $this->author; return $this->yearpublished; sprintf($this->title, $this->author, $this->yearpublished); }
to
function summary(){ return sprintf('%s %s %s',$this->title, $this->author, $this->yearpublished); }
Comments
Post a Comment