Bug #72985 [Opn]: Reflections with Nullable Strings producing crash.
| From: | andremohren at gmail dot com | Date: | Wed, 31 Aug 2016 09:20:26 +0000 |
| Subject: | Bug #72985 [Opn]: Reflections with Nullable Strings producing crash. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203702@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72985&edit=1
ID: 72985
User updated by: andremohren at gmail dot com
Reported by: andremohren at gmail dot com
Summary: Reflections with Nullable Strings producing crash.
Status: Open
Type: Bug
-Package: PDO Core
+Package: Reproducible crash
Operating System: Windows 7 Professional 64bit
PHP Version: 7.1.0beta3
Block user comment: N
Private report: N
New Comment:
Corrected wrong Package - sorry.
Previous Comments:
------------------------------------------------------------------------
[2016-08-31 07:22:18] andremohren at gmail dot com
Description:
------------
When using Reflections and accessing the method return type or parameter type, php crashes might
crash if the parameter is nullable.
The first checked class works flawless, the second class produces the crash.
Test script:
---------------
<?php
function randomName(int $length) : string
{
return implode('', array_map(function () : string {
return chr(65 + rand(0, 25) + (rand(0, 1) === 0 ? 0 : 32));
}, array_fill(0, $length, '')));
}
function createTestClass(int $classNameLength, int $numMethods, int $methodNameLength) : string
{
do {
$className = randomName($classNameLength);
} while (class_exists($className));
$methods = [];
for ($m = 0; $m < $numMethods; $m++) {
do {
$methodName = randomName($methodNameLength);
} while (array_key_exists($methodName, $methods));
$methods[$methodName] = 'public function ' . $methodName . '(?string $param)
: ?string { return $param; }';
}
eval(implode(PHP_EOL, ['class ' . $className . '{', implode(PHP_EOL,
$methods), '}']));
return $className;
}
function testClassReflections(string $className) : void
{
$class = new ReflectionClass($className);
$methods = [];
foreach ($class->getMethods() as $method) {
$parameters = [];
foreach ($method->getParameters() as $parameter) {
$parameters[] = $parameter->getType() . ' ' . $parameter->getName();
}
$methods[] = $method->getReturnType() . ' ' . $method->getName() .
'(' . implode(', ', $parameters) . ')';
}
printf('%s { %s }' . PHP_EOL, $class->getName(), implode(', ',
$methods));
}
function test(int $numClasses, int $classNameLength, int $numMethods, int $methodNameLength) : void
{
printf('{ classes: { num: %d, length: %d }, methods: { num: %d, length: %d } }' .
PHP_EOL,
$numClasses, $classNameLength, $numMethods, $methodNameLength
);
for ($c = 0; $c < $numClasses; $c++) {
testClassReflections(createTestClass($classNameLength, $numMethods, $methodNameLength));
}
}
// This does not crash when first parameter is 1.
test(2, 10, 5, 10);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72985&edit=1