Solved

__get to echo name

Posted on 2014-04-29
2
273 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Read a remote csv file from a https URL 8 47
Wordpress Security 29 48
Extracting content from meta tag PHP MYHTML DOM 3 20
Correct syntax for subdirectories 9 18
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

839 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