Browse Source
Fixed Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error)
Fixed Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error)
- aliases that are not actually matching anything are treated as errors now. This will make sure that all methods that are expected to be in a class are actually there, or in case a trait changed for instance, that the code breaks already on composition - Precedence declarations are also checked to ensure that the method which is supposed to take precedence actually exists, however, the other traits mentioned in the declaration are not regarded. We are more lenient here, since this avoids unnecessary fragility. - fixed another seamingly unrelated test which broke in the progress but wasn't clear before either.pull/7/head
6 changed files with 147 additions and 3 deletions
-
17Zend/tests/traits/bug60165a.phpt
-
17Zend/tests/traits/bug60165b.phpt
-
22Zend/tests/traits/bug60165c.phpt
-
21Zend/tests/traits/bug60165d.phpt
-
4Zend/tests/traits/language011.phpt
-
69Zend/zend_compile.c
@ -0,0 +1,17 @@ |
|||
--TEST-- |
|||
Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) |
|||
--FILE-- |
|||
<?php |
|||
|
|||
trait A { |
|||
public function bar() {} |
|||
} |
|||
|
|||
class MyClass { |
|||
use A { |
|||
nonExistent as barA; |
|||
} |
|||
} |
|||
|
|||
--EXPECTF-- |
|||
Fatal error: An alias (barA) was defined for method nonExistent(), but this method does not exist in %s on line %d |
|||
@ -0,0 +1,17 @@ |
|||
--TEST-- |
|||
Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) |
|||
--FILE-- |
|||
<?php |
|||
|
|||
trait A { |
|||
public function bar() {} |
|||
} |
|||
|
|||
class MyClass { |
|||
use A { |
|||
A::nonExistent as barA; |
|||
} |
|||
} |
|||
|
|||
--EXPECTF-- |
|||
Fatal error: An alias was defined for A::nonExistent but this method does not exist in %s on line %d |
|||
@ -0,0 +1,22 @@ |
|||
--TEST-- |
|||
Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) |
|||
--FILE-- |
|||
<?php |
|||
|
|||
trait A { |
|||
public function bar() {} |
|||
} |
|||
|
|||
trait B { |
|||
public function foo() {} |
|||
} |
|||
|
|||
class MyClass { |
|||
use A, B { |
|||
foo as fooB; |
|||
baz as foobar; |
|||
} |
|||
} |
|||
|
|||
--EXPECTF-- |
|||
Fatal error: An alias (foobar) was defined for method baz(), but this method does not exist in %s on line %d |
|||
@ -0,0 +1,21 @@ |
|||
--TEST-- |
|||
Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) |
|||
--FILE-- |
|||
<?php |
|||
|
|||
// The same is true for the insteadof operator to resolve conflicts |
|||
|
|||
trait A {} |
|||
|
|||
trait B { |
|||
public function bar() {} |
|||
} |
|||
|
|||
class MyClass { |
|||
use A, B { |
|||
A::bar insteadof B; |
|||
} |
|||
} |
|||
|
|||
--EXPECTF-- |
|||
Fatal error: A precedence rule was defined for A::bar but this method does not exist in %s on line %d |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue