Jump to content

echo nothing?


begeiste

Recommended Posts

Hi,

I have created a class "friendClass" and tried to echo it. It prints nothing without any errors, not sure what was it going on? Any helps would be appreciated!

        class friendClass{
            
                //attributes - variable
                public $name;
                public $sex;
                public $title;
                public $country;
                
                //methods - function
                public function eat(){}
                public function watch(){}
                public function drive(){}
                public function speak(){}    
                
            }
            
            $friend1 = new friendClass;
            $friend2 = new friendClass;
            $friend3 = new friendClass;
            $friend4 = new friendClass;
            
            $friend1 -> name = "Bach";
            $friend1 -> title = "Muscian";
            $friend1 -> sex = "Male";
            $friend1 -> country = "Germany";
            
            $friend1 -> eat("Bread");
            $friend1 -> speak("German");
            $friend1 -> drive("Horse");
            $friend1 -> watch("Beethoven");
            
            echo "Name is: ".$friend1->name; 

Link to comment
https://forums.phpfreaks.com/topic/251578-echo-nothing/
Share on other sites

Your code outputs - Name is: Bach

 

If you didn't get anything, either your actual code contains a php error, your opening php tag isn't a full <?php tag, php isn't installed and running on your server, or you didn't browse to the URL of your page in your browser. What does a 'view source' of the page in your browser show? What URL did you browse to (it should be something like http://localhost/your_file.php on your local development system)?

Link to comment
https://forums.phpfreaks.com/topic/251578-echo-nothing/#findComment-1290378
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.