Solved

__get to echo name

Posted on 2014-04-29
2
266 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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
The viewer will learn how to dynamically set the form action using jQuery.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now