Jump to content

PHP OOP Classes/Objects tutorial


Muck A. Round
 Share

Recommended Posts

When I "Try it yourself" on the first example, and hit RUN, nothing appears in the right box.  Is this correct?  If so, I'm not sure of the point.  Below is the code for that example.

<!DOCTYPE html>
<html>
<body>

<?php
class Fruit {
  // Properties
  public $name;
  public $color;

  // Methods
  function set_name($name) {
    $this->name = $name;
  }
  function get_name() {
    return $this->name;
  }
}
?>
 
</body>
</html>

Link to comment
Share on other sites

That is correct. The code defines a class, but nothing will happen if you don't use the class.

Do they really have a try-it example with this code?

Link to comment
Share on other sites

23 hours ago, Ingolme said:

That is correct. The code defines a class, but nothing will happen if you don't use the class.

Do they really have a try-it example with this code?

Yes - that's the code copy/pasted from the "Try it yourself".   So they could have explained nothing would happen (or even not bother making it a "Try it yourself" when trying it doesn't do anything except show you the code again?).   Looking at subsequent examples, I see that more code is necessary.  It's good to know what these layers of code do, but was a little confusing when you hit the button and nothing happens.

Link to comment
Share on other sites

On 8/5/2021 at 10:21 AM, Ingolme said:

Do they really have a try-it example with this code?

It seems there are more examples later in this section where they have a "Try it yourself" but the code doesn't produce anything in the output.  It would be clearer if they either modified the code to produce at least something, or explain that the code won't produce any output because xyz. 

Link to comment
Share on other sites

At the bottom of each page they have a button labelled "report error". You can provide suggestions to them from there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...