-
Notifications
You must be signed in to change notification settings - Fork 1
/
9.class.php
51 lines (37 loc) · 1001 Bytes
/
9.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
print "\n\n--- static and non-static method ---\n\n";
class Foo{
public $a = "a";
public function a(){
$this->a = "a()\n";
return $this->a;
}
static $b = "b";
public static function bb(){
self::$b = "bb\n";
return self::$b;
}
}
//non-static method called via class instantiation
$foo = new Foo();
echo "property: $foo->a \n"; //non static
echo "property: ".Foo::$b." \n"; //static
echo "menthod: {$foo->a()}";
//static method called with scope resolution operator
echo Foo::bb();
//static method called via class instantiation
echo $foo->bb();
print "\n\n--- class constant ---\n\n";
class MyClass {
const CONSTANT = "A Constant";
function showConstant(){
echo self::CONSTANT . "\n";
}
}
echo MyClass::CONSTANT . "\n";
$myClassName = "MyClass";
echo $myClassName::CONSTANT . "\n";
$myClassName::showConstant();
$initMyClass = new MyClass();
$initMyClass->showConstant();
echo $initMyClass::CONSTANT;