Last active
August 29, 2015 14:04
-
-
Save smalyshev/f4d0c1502fa2411478ff to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
function makeClass($origClass) { | |
$rc = new ReflectionClass($origClass); | |
if($rc->isInterface()) { | |
echo "Interface $origClass, skipped\n"; | |
return; | |
} | |
if($rc->isFinal()) { | |
echo "FINAL $origClass, skipped\n"; | |
return; | |
} | |
if($rc->isAbstract()) { | |
echo "ABSTRACT $origClass, skipped\n"; | |
return; | |
} | |
$ctor = $rc->getConstructor(); | |
if($ctor && $ctor->isFinal()) { | |
echo "FINAL CTOR $origClass, skipped\n"; | |
return; | |
} | |
$badClassName = "BadClass_$origClass"; | |
$badclass = "class $badClassName extends $origClass { public function __construct() {} }"; | |
eval($badclass); | |
$foo = new $badClassName(); | |
// These produce errors when called on uninitialized objects, so we exclude them | |
// Luckily, producing error is OK for our case | |
$badNames = [ | |
'DateTime::__wakeup', 'DateTimeImmutable::__wakeup', 'DatePeriod::__wakeup', 'DOMDocument::registerNodeClass','SplFileInfo::getPerms', | |
"SplFileInfo::getInode",'SplFileInfo::getSize', "SplFileInfo::getOwner", "SplFileInfo::getGroup","SplFileInfo::getATime","SplFileInfo::getMTime", | |
"SplFileInfo::getCTime", "SplFileInfo::getType", "SplFileInfo::isWritable", "SplFileInfo::isReadable", "SplFileInfo::isExecutable", | |
"SplFileInfo::isFile", "SplFileInfo::isDir", "SplFileInfo::isLink", "SplFileInfo::getFileInfo", "SplFileInfo::openFile", | |
"FilesystemIterator::key","FilesystemIterator::current","RecursiveDirectoryIterator::getChildren", | |
'GlobIterator::count', "SplFixedArray::setSize", "SessionHandler::open", "SessionHandler::close", "SessionHandler::read", "SessionHandler::write", | |
"SessionHandler::destroy", "SessionHandler::gc", "SessionHandler::create_sid", 'ReflectionFunction::__toString', 'ReflectionFunction::isDisabled', | |
'SoapServer::SoapServer', | |
]; | |
foreach($rc->getMethods(ReflectionMethod::IS_PUBLIC) as $rm) { | |
$name = $rm->getDeclaringClass()->getName() . "::" . $rm->getName(); | |
if(in_array($name, $badNames)) { | |
echo "SKIPPED: {$rc->getName()}::{$rm->getName()}\n"; | |
continue; | |
} | |
$args = []; | |
foreach($rm->getParameters() as $param) { | |
if($param->isOptional()) { | |
continue; | |
} | |
if($param->allowsNull()) { | |
$args[] = null; | |
continue; | |
} | |
if($param->isArray()) { | |
$args[] = [mt_rand()]; | |
continue; | |
} | |
$args[] = mt_rand(0, 1000); | |
} | |
var_dump($name, $args); | |
flush(); | |
$obj = new $badClassName(); | |
try { | |
$rm->invokeArgs($obj, $args); | |
} catch(Exception $e) { | |
echo $e; | |
} | |
} | |
} | |
$le = get_loaded_extensions(); | |
sort($le); | |
foreach($le as $ext) { | |
echo "\n===== $ext ====\n"; | |
if($ext == 'Reflection') continue; | |
$re = new ReflectionExtension($ext); | |
foreach($re->getClassNames() as $c) | |
{ | |
makeClass($c); | |
} | |
} | |
echo "\nDONE\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment