Created
October 31, 2017 07:22
-
-
Save anil477/fcfc398936890af7069f8426a85c1321 to your computer and use it in GitHub Desktop.
__set and __get PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if $firstName is made public then __set won't be called | |
<?php | |
class Person{ | |
private $firstName; | |
public function __get($propertyName){ | |
echo "attempted to read non-existing property: $propertyName | |
"; | |
} | |
public function __set($propertyNane, $propertyValue){ | |
echo "attempted to write to non-existing property: $propertyNane | |
"; | |
} | |
} | |
$p = new Person(); | |
$p->firstName = 'Doe'; | |
echo $p->firstName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment