Skip to content

Instantly share code, notes, and snippets.

@koike koike/overload.php
Created Nov 4, 2016

Embed
What would you like to do?
<?php
/*
オーバーロード
http://php.net/manual/ja/language.oop5.overloading.php
*/
class Test
{
private $data = [];
public function __set($name, $value)
{
return $this->data[$name] = $value;
}
public function __get($name)
{
return $this->data[$name];
}
public function __call($name, $args)
{
return "__call => {$name}(...)";
}
public static function __callStatic($name, $args)
{
return "__callStatic => {$name}(...)";
}
public static function println($mes)
{
print($mes);
print("\n");
}
}
$instance = new Test();
$instance->test = 'abc';
Test::println($instance->test);
Test::println($instance->test());
Test::println(Test::test());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.