Edit report at https://bugs.php.net/bug.php?id=72985&edit=1
ID: 72985
Comment by: andremohren at gmail dot com
Reported by: andremohren at gmail dot com
Summary: Reflections with Nullable Strings producing crash.
Status: Feedback
Type: Bug
Package: Reproducible crash
Operating System: Windows 7 Professional 64bit
PHP Version: 7.1.0beta3
Block user comment: N
Private report: N
New Comment:
Cannot use any of both ways to reproduce, as i cannot install software on this machine due to the
lack of permissions on our business machines.
Previous Comments:
------------------------------------------------------------------------
[2016-08-31 12:21:54] ab@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php
for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php
for Win32
Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.
------------------------------------------------------------------------
[2016-08-31 09:20:26] andremohren at gmail dot com
Corrected wrong Package - sorry.
------------------------------------------------------------------------
[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