Skip to content

Instantly share code, notes, and snippets.

@anil477
Created October 31, 2017 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anil477/fcfc398936890af7069f8426a85c1321 to your computer and use it in GitHub Desktop.
Save anil477/fcfc398936890af7069f8426a85c1321 to your computer and use it in GitHub Desktop.
__set and __get PHP
// 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