xref: /PHP-7.4/Zend/tests/lsb_001.phpt (revision 782352c5)
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==DONE==
51--EXPECT--
52TestClassStatic
53TestClassConst
54TestClassFunction
55ChildClassStatic
56ChildClassConst
57ChildClassFunction
58TestClassStatic
59TestClassConst
60TestClassFunction
61==DONE==
62