-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #79969: Wrong error message in strict mode in ReflectionMethod::_construct #5995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jdomenechb
wants to merge
3
commits into
php:PHP-7.3
from
jdomenechb:bug-79979-strict-type-check-reflection-method
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,9 @@ Steve Seear <[email protected]> | |
--FILE-- | ||
<?php | ||
|
||
try { | ||
new ReflectionMethod(); | ||
} catch (TypeError $re) { | ||
echo "Ok - ".$re->getMessage().PHP_EOL; | ||
} | ||
try { | ||
new ReflectionMethod('a', 'b', 'c'); | ||
} catch (TypeError $re) { | ||
echo "Ok - ".$re->getMessage().PHP_EOL; | ||
} | ||
new ReflectionMethod(); | ||
new ReflectionMethod('a', 'b', 'c'); | ||
|
||
|
||
class C { | ||
public function f() {} | ||
|
@@ -43,8 +36,9 @@ var_dump($rm->getName(1)); | |
|
||
?> | ||
--EXPECTF-- | ||
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given | ||
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given | ||
Warning: Wrong parameter count for ReflectionMethod::__construct() in %s on line %d | ||
|
||
Warning: Wrong parameter count for ReflectionMethod::__construct() in %s on line %d | ||
|
||
Warning: ReflectionMethod::isFinal() expects exactly 0 parameters, 1 given in %s on line %d | ||
NULL | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,20 +12,11 @@ class TestClass | |
} | ||
} | ||
|
||
echo "Too few arguments:\n"; | ||
$methodInfo = new ReflectionMethod(); | ||
|
||
try { | ||
echo "Too few arguments:\n"; | ||
$methodInfo = new ReflectionMethod(); | ||
} catch (TypeError $re) { | ||
echo "Ok - ".$re->getMessage().PHP_EOL; | ||
} | ||
try { | ||
echo "\nToo many arguments:\n"; | ||
$methodInfo = new ReflectionMethod("TestClass", "foo", true); | ||
} catch (TypeError $re) { | ||
echo "Ok - ".$re->getMessage().PHP_EOL; | ||
} | ||
|
||
echo "\nToo many arguments:\n"; | ||
$methodInfo = new ReflectionMethod("TestClass", "foo", true); | ||
|
||
try { | ||
//invalid class | ||
|
@@ -50,12 +41,14 @@ try{ | |
} | ||
|
||
?> | ||
--EXPECT-- | ||
--EXPECTF-- | ||
Too few arguments: | ||
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given | ||
|
||
Warning: Wrong parameter count for ReflectionMethod::__construct() in %s on line %d | ||
|
||
Too many arguments: | ||
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given | ||
|
||
Warning: Wrong parameter count for ReflectionMethod::__construct() in %s on line %d | ||
Ok - Class InvalidClassName does not exist | ||
Ok - The parameter class is expected to be either a string or an object | ||
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given | ||
Ok - ReflectionMethod::__construct() expects parameter 2 to be string, array given | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: missing new line before EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Bug #79969: ReflectionMethod::__construct throws incorrect exception when 2nd parameter is int | ||
--FILE-- | ||
<?php | ||
declare(strict_types=1); | ||
|
||
new ReflectionMethod('xxx', 1); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught TypeError: ReflectionMethod::__construct() expects parameter 2 to be string, int given in %s | ||
Stack trace: | ||
#0 %s(%d): ReflectionMethod->__construct('xxx', 1) | ||
#1 {main} | ||
thrown in %s on line %d |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should do the trick, for PHP 7.3 and 7.4, the person doing the merge-up to master/PHP 8.0 will need to change it to
zend_wrong_parameters_count_error()
as the former API has been removed in master.