1

Its not working. print only name. how can i print all properties? i cant find my error. please someone solve it with description. my code is...

 <?php
   class pavel{
     public $name="pavel"; 
     public $age="23";
     public $degree="CSE";
      public function myself_set($a,$b,$c){
        $this->name=$a;
        $this->age=$b;
        $this->degree=$c;
      }

      public function myself_get(){
        return  $this->name."<br />";
        return  $this->age."<br />";
        return  $this->degree."<br />";
      }


   }
   $obj = new pavel();
   $obj->myself_set("parvej","24","BSc");
   echo $obj->myself_get();
   echo $obj->myself_get(); 
   ?>
1
  • 1
    return statement ends the execution of a function/method Commented Sep 4, 2016 at 15:00

1 Answer 1

1

In this function:

public function myself_get(){
    return  $this->name."<br />";
    return  $this->age."<br />";
    return  $this->degree."<br />";
}

... only the first return statement is executed, at which point the function exits back to the caller. So the other return statements are "dead code": they will never be executed.

Change to something like:

public function myself_get(){
    return  $this->name."<br />".
            $this->age."<br />".
            $this->degree."<br />";
}

This will return one string made up of the three values.

See it run on eval.in

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

2 Comments

it return only name
Did you make a mistake? See it run on eval.in/635087. It outputs all three values.

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.