Complete the code to define the magic method that is called when reading inaccessible properties.
<?php class Person { private $data = []; public function [1]($name) { return $this->data[$name] ?? null; } } ?>
The __get method is called when reading inaccessible or undefined properties.
Complete the code to define the magic method that is called when writing to inaccessible properties.
<?php class Person { private $data = []; public function [1]($name, $value) { $this->data[$name] = $value; } } ?>
The __set method is called when writing to inaccessible or undefined properties.
Fix the error in the magic method name to correctly handle property reading.
<?php class Person { private $data = []; public function [1]($name) { return $this->data[$name] ?? null; } } ?>
The correct magic method name for reading inaccessible properties is __get.
Fill both blanks to complete the magic methods for property access.
<?php class Person { private $data = []; public function [1]($name) { return $this->data[$name] ?? null; } public function [2]($name, $value) { $this->data[$name] = $value; } } ?>
The __get method handles reading inaccessible properties, and __set handles writing to them.
Fill all three blanks to create a class that uses __get and __set to store and retrieve properties in a private array.
<?php class DataStore { private $storage = []; public function [1]($key) { return $this->storage[[2]] ?? null; } public function [3]($key, $value) { $this->storage[$key] = $value; } } ?>
The __get method uses the $key parameter to access the private storage array. The __set method sets values in the storage.