xref: /PHP-8.0/Zend/tests/lsb_001.phpt (revision f8d79582)
1--TEST--
2ZE2 Late Static Binding in a static function
3--FILE--
4<?php
5
6class TestClass {
7    protected static $staticVar = 'TestClassStatic';
8    const CLASS_CONST = 'TestClassConst';
9
10    protected static function staticFunction() {
11        return 'TestClassFunction';
12    }
13
14    public static function testStaticVar() {
15        return static::$staticVar;
16    }
17
18    public static function testClassConst() {
19        return static::CLASS_CONST;
20    }
21
22    public static function testStaticFunction() {
23        return static::staticFunction();
24    }
25}
26
27class ChildClass1 extends TestClass {
28    protected static $staticVar = 'ChildClassStatic';
29    const CLASS_CONST = 'ChildClassConst';
30
31    protected static function staticFunction() {
32        return 'ChildClassFunction';
33    }
34}
35
36class ChildClass2 extends TestClass {}
37
38echo TestClass::testStaticVar() . "\n";
39echo TestClass::testClassConst() . "\n";
40echo TestClass::testStaticFunction() . "\n";
41
42echo ChildClass1::testStaticVar() . "\n";
43echo ChildClass1::testClassConst() . "\n";
44echo ChildClass1::testStaticFunction() . "\n";
45
46echo ChildClass2::testStaticVar() . "\n";
47echo ChildClass2::testClassConst() . "\n";
48echo ChildClass2::testStaticFunction() . "\n";
49?>
50--EXPECT--
51TestClassStatic
52TestClassConst
53TestClassFunction
54ChildClassStatic
55ChildClassConst
56ChildClassFunction
57TestClassStatic
58TestClassConst
59TestClassFunction
60