Need Help : Code not showing result

Plz anybody can help me why the below php code doesn’t work:

[php] <?php
class PrintName
{
var $name;

                   function show_name()
                   {
                        echo "\n";
                        echo "The name passed to this method is $name.", "\n";
                        echo "Hi $name! How are you doing?", "\n", "\n";
                   }
             }
             $obj1 = new PrintName;   
            $obj1 -> name = "George";  
            $obj1 -> show_name();   

?>[/php]

The output would be but not showing :

The name passed to this method is George.
Hi George How are you doing?

When referencing variables (inside of a class), that belong to that class, you have to use the $this-> prefix:

[php]echo "The name passed to this method is ", $this->name, “.\n”;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service