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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -