Bug #72985 [NEW]: Reflections with Nullable Strings producing crash.
| From: | andremohren at gmail dot com | Date: | Wed, 31 Aug 2016 07:22:25 +0000 |
| Subject: | Bug #72985 [NEW]: Reflections with Nullable Strings producing crash. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-203697@lists.php.net to get a copy of this message | ||
From: andremohren at gmail dot com
Operating system: Windows 7 Professional 64bit
PHP version: 7.1.0beta3
Package: PDO Core
Bug Type: Bug
Bug description:Reflections with Nullable Strings producing crash.
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 bug report at https://bugs.php.net/bug.php?id=72985&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72985&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72985&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72985&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72985&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72985&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72985&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72985&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72985&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72985&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72985&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72985&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72985&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72985&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72985&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72985&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72985&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72985&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72985&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72985&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72985&r=mysqlcfg