Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

__get to echo name

Posted on 2014-04-29
2
Medium Priority
?
283 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

972 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