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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.