Skip to content

Commit f39d12c

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
2 parents 22ae9ef + 9a44a98 commit f39d12c

File tree

6 files changed

+77
-4
lines changed

6 files changed

+77
-4
lines changed

Zend/tests/traits/bug64235.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #64235 (Insteadof not work for class method in 5.4.11)
3+
--FILE--
4+
<?php
5+
6+
class TestParentClass
7+
{
8+
public function method()
9+
{
10+
print_r('Parent method');
11+
print "\n";
12+
}
13+
}
14+
15+
trait TestTrait
16+
{
17+
public function method()
18+
{
19+
print_r('Trait method');
20+
print "\n";
21+
}
22+
}
23+
24+
class TestChildClass extends TestParentClass
25+
{
26+
use TestTrait
27+
{
28+
TestTrait::method as methodAlias;
29+
TestParentClass::method insteadof TestTrait;
30+
}
31+
}
32+
?>
33+
--EXPECTF--
34+
Fatal error: Class TestParentClass is not a trait, Only traits may be used in 'as' and 'insteadof' statements in %sbug64235.php on line %d

Zend/tests/traits/bug64235b.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #64235 (Insteadof not work for class method in 5.4.11)
3+
--FILE--
4+
<?php
5+
6+
class TestParentClass
7+
{
8+
public function method()
9+
{
10+
print_r('Parent method');
11+
print "\n";
12+
}
13+
}
14+
15+
trait TestTrait
16+
{
17+
public function method()
18+
{
19+
print_r('Trait method');
20+
print "\n";
21+
}
22+
}
23+
24+
class TestChildClass extends TestParentClass
25+
{
26+
use TestTrait
27+
{
28+
TestTrait::method as methodAlias;
29+
TestParentClass::method as TestParent;
30+
}
31+
}
32+
33+
?>
34+
--EXPECTF--
35+
Fatal error: Class TestParentClass is not a trait, Only traits may be used in 'as' and 'insteadof' statements in %sbug64235b.php on line %d

Zend/tests/traits/language015.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ class C {
1414
}
1515
}
1616
--EXPECTF--
17-
Fatal error: Trait T2 is not used in %s on line %d
17+
Fatal error: Required Trait T2 wasn't added to C in %slanguage015.php on line %d

Zend/tests/traits/language016.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ class C {
1414
}
1515
}
1616
--EXPECTF--
17-
Fatal error: Trait T2 is not used in %s on line %d
17+
Fatal error: Required Trait T2 wasn't added to C in %slanguage016.php on line %d

Zend/tests/traits/language017.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ class C {
1414
}
1515
}
1616
--EXPECTF--
17-
Fatal error: Trait T2 is not used in %s on line %d
17+
Fatal error: Required Trait T2 wasn't added to C in %slanguage017.php on line %d

Zend/zend_compile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4048,12 +4048,16 @@ static void zend_check_trait_usage(zend_class_entry *ce, zend_class_entry *trait
40484048
{
40494049
zend_uint i;
40504050

4051+
if ((trait->ce_flags & ZEND_ACC_TRAIT) != ZEND_ACC_TRAIT) {
4052+
zend_error(E_COMPILE_ERROR, "Class %s is not a trait, Only traits may be used in 'as' and 'insteadof' statements", trait->name);
4053+
}
4054+
40514055
for (i = 0; i < ce->num_traits; i++) {
40524056
if (ce->traits[i] == trait) {
40534057
return;
40544058
}
40554059
}
4056-
zend_error(E_COMPILE_ERROR, "Trait %s is not used", trait->name);
4060+
zend_error(E_COMPILE_ERROR, "Required Trait %s wasn't added to %s", trait->name, ce->name);
40574061
}
40584062
/* }}} */
40594063

0 commit comments

Comments
 (0)