Solved

__get to echo name

Posted on 2014-04-29
2
275 Views
Last Modified: 2014-04-29
class person{
  
  public function __construct($name,$age){
  $this->name=$name;
  $this->age=$age;  
  }
  public function __get($variable){
    echo '<h1>this it the variable: '.$variable.'</h1>';
  }
}


$obj=new person('jon',29);
echo '<br>name is: '.$obj->__get();

Open in new window





I remember that the magic method __get is called but I forget how to call in order to echo name
0
Comment
Question by:rgb192
2 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
ID: 40031114
This should do it:

class person{
  public $name;
  
  public function __construct($name,$age){
  $this->name=$name;
  $this->age=$age;  
  }
  public function __get($variable){
    echo '<h1>this it the variable: '.$variable.'</h1>';
  }
}


$obj=new person('jon',29);
echo '<br>name is: '.$obj->__get($obj->name); 

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 40031157
thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question