Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflection: FilesystemIterator uses unknown class as type-hint #2057

Closed
Ocramius opened this issue Mar 13, 2014 · 7 comments
Closed

Reflection: FilesystemIterator uses unknown class as type-hint #2057

Ocramius opened this issue Mar 13, 2014 · 7 comments

Comments

@Ocramius
Copy link
Contributor

It seems like FilesystemIterator#setFlags() has a parameter hinted int $flags.

While this is obviously working within HHVM, reflection chokes on it with a HipHop Fatal error: Uncaught exception 'ReflectionException' with message 'Class int does not exist

Not sure what the solution here would be. Is there a list of scalar typehints that should be excluded from trying to introspect method parameters?

The issue currently affects Zend\Code\Reflection and related API.

Note: the simplest resolution is to just remove the hint for now.

Edit: #1600 is actually a possible fix for this.

@thekid
Copy link
Contributor

thekid commented Mar 17, 2014

(Moving the discussion back from the commit comments to here)

Can you give a short view into what's being done here?

Assuming the code reads something like this:

$param= new ReflectionParameter(...);
if ($param->isArray()) {
  // Handle array type hint
} else if ($param->isCallable()) {
  // Handle callable type hint (PHP 5 >= 5.4.0)
} else if (null !== ($class= $param->getClass())) {
  // Handle classes
} else {
  // No type hint
}

...I don't see how this breaks; we'll run into the No type hint branch in both HHVM (with #1600 applied) and PHP.

@thekid
Copy link
Contributor

thekid commented Mar 17, 2014

Putting the above script into a test.php and letting it run with various environments:

PHP 5.5.10

Timm@slate ~
$ /cygdrive/c/Programme/php-5.5.10/php test.php FilesystemIterator::setFlags
Primitive

HHVM 2.4.0:

friebe@xpsrv ~/devel/hhvm $ hhvm test.php FilesystemIterator::setFlags
HipHop Fatal error: Uncaught exception 'ReflectionException' with message 'Class int does not exist' in :
Stack trace:
#0 (): ReflectionClass->__construct()
#1 /home/friebe/devel/hhvm/test.php(18): ReflectionParameter->getClass()
#2 {main}

HHVM 2.5.0-dev with #1600 applied:

friebe@xpsrv ~/devel/hhvm $ ./hphp/hhvm/hhvm test.php FilesystemIterator::setFlags
Primitive

@Ocramius
Copy link
Contributor Author

@thekid ah, I completely missed the branch where that commit was: apologies!

Yes, if the "no-hint" path will be hit, then we're fine.

Sorry about all the noise, I just misunderstood your fix.

@thekid
Copy link
Contributor

thekid commented Mar 17, 2014

Sorry about all the noise

No problem. Also, the fix is not yet merged:)

@scannell
Copy link
Contributor

scannell commented Apr 2, 2014

Thanks for reporting this.

@fredemmott
Copy link
Contributor

Sorry, we weren't able to take #1600 as it changed too much at the same time, and it was impractical to debug all the issues it raised. I'll take a look at this now.

It seems like this demonstrates the issue:

<?php

function foo(int $bar) {
};

$rp = new ReflectionParameter('foo', 'bar');
var_dump($rp->getClass());
[fredemmott@devbig076 ~] hhvm test.php

Fatal error: Uncaught exception 'ReflectionException' with message 'Class int does not exist' in :
Stack trace:
#0 (): ReflectionClass->__construct()
#1 /home/fredemmott/test.php(7): ReflectionParameter->getClass()
#2 {main}

It should output NULL.

@fredemmott
Copy link
Contributor

Fix up for review internally (changing ReflectionParameter::getClass()). FB: D1356779

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants