Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Object-Oriented PHP Basics Building the Recipe Access

Obayanju Damilare
Obayanju Damilare
3,383 Points

Read and write

what does it mean to read and write a method or property in PHP.

Diar Selimi
Diar Selimi
1,341 Points

It means giving the specific property a value or getting a value from a property.

1 Answer

Mochammad Rezza
Mochammad Rezza
4,778 Points

The read it's mean that you can access/see the property directly within class. The write it's mean that you can set the property directly within class. for example

class instance
{
//property 
 public $number = 5;

}
$a = new instance();
$a->instance = 10; // you can write/set directly property number
echo $a->instance; // you can read directly property number

Otherwise you can access directly property $number if the visibility is private.

class instance
{
 private $number = 5;

// you must using this to read variable $number
  public function getNumber()
  {
    return $this->number;
  }

}
$a = new instance();
$a->instance = 10; // you can't write/set directly variable number (wrong)
echo $a->instance; // you can't read directly variable number (wrong)

$a->getNumber(); // correct

you can check more example in this link -> http://php.net/manual/en/language.oop5.visibility.php