|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-08-31 09:20 UTC] andremohren at gmail dot com
-Package: PDO Core
+Package: Reproducible crash
[2016-08-31 09:20 UTC] andremohren at gmail dot com
[2016-08-31 12:21 UTC] ab@php.net
-Status: Open
+Status: Feedback
[2016-08-31 12:21 UTC] ab@php.net
[2016-08-31 12:29 UTC] andremohren at gmail dot com
[2016-09-01 06:39 UTC] andremohren at gmail dot com
-Status: Feedback
+Status: Open
[2016-09-01 06:39 UTC] andremohren at gmail dot com
[2016-09-01 08:22 UTC] nikic@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2016-09-01 08:22 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 10:00:01 2025 UTC |
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);