Answer the question
In order to leave comments, you need to log in
Why is the access method not working?
Hello!
This code should not allow the return to be set to less than 20, but any value can be set - a mess. How to fix?
<?php
class Car{
public $age = 30;
function __set($name, $value){
if($value>20){ //Возвраст может быть только больше 20-и
$this->$name = $value;
}
}
}
$car = new Car();
$car->age = 15; //Такого делать нельзя!
echo $car->age;
?>
Accessors do not apply to private properties.
The following statement will implicitly call the __set() function:$a->attribute = 5;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question