classs static 활용법
Server Side/PHP2016. 8. 9. 20:56
class Foo
{
public static $my_static = 'foo';
public function staticValue() {
return self::$my_static;
}
}
class Bar extends Foo
{
public function fooStatic() {
return parent::$my_static;
}
}
print Foo::$my_static . "\n";
$foo = new Foo();
print $foo->staticValue() . "\n";
print $foo->my_static . "\n"; // Undefined "Property" my_static
print $foo::$my_static . "\n";
$classname = 'Foo';
print $classname::$my_static . "\n"; // As of PHP 5.3.0
print Bar::$my_static . "\n";
$bar = new Bar();
print $bar->fooStatic() . "\n";
/////////////////////////////////
private static function write($binary, $format = 'v')
{
echo pack($format, $binary);
}
'Server Side > PHP' 카테고리의 다른 글
| 코드이그나이터 설정 (0) | 2016.08.17 |
|---|---|
| PHP PDO 작성 및 변환 예 (0) | 2016.08.15 |
| foreach 로 다차원 배열 만들기 (0) | 2016.08.08 |
| PHP 로 XML/RSS 파일 생성하기 (0) | 2016.08.07 |
| AJAX 이용해서 PHP 첨부파일 삭제 (0) | 2016.08.07 |