Skip to content

ClassExistenceResource::isFresh autoloads classes ignoring missing interfaces #28748

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

Closed
ausi opened this issue Oct 6, 2018 · 4 comments
Closed

Comments

@ausi
Copy link
Contributor

ausi commented Oct 6, 2018

Symfony version(s) affected: 4.1.6

Description
While debugging an issue with a class that is missing an interface (contao/contao#89) I was able to reduce the bug to a simple reproduction case with the ClassExistenceResource::isFresh() method.

The method autoloads a class even though it implements a missing interface. I’m not sure if this might be bug in PHP too, because loading a class without one of its interfaces should not be possible I think?

How to reproduce

composer.json

{
    "autoload": { "classmap": [ "Foo.php" ] },
    "require": { "symfony/config": "4.1.6" }
}

Foo.php

<?php
class Foo implements NonExistentInterface {
    public static function bar() { var_dump(__METHOD__); }
}

test.php

<?php
require __DIR__.'/vendor/autoload.php';
$resource = new \Symfony\Component\Config\Resource\ClassExistenceResource('Foo', false);

// The following line autoloads the Foo class,
// even though it implements a non-existent interface
$resource->isFresh(1);

// The following lines would normally result in a ClassNotFoundException for the missing interface.
var_dump((new \ReflectionClass('Foo'))->getInterfaces());
// array(0) {}
Foo::bar();
// string(8) "Foo::bar"
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 6, 2018

That's PHP, not Symfony, see https://3v4l.org/1pHqv

@ausi
Copy link
Contributor Author

ausi commented Oct 6, 2018

👍
I will report it to PHP then.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 6, 2018

Thanks, please link the bug report here then we can close :)

@ausi
Copy link
Contributor Author

ausi commented Oct 6, 2018

PHP bug: https://bugs.php.net/bug.php?id=76980

@nicolas-grekas thank you for the reduced test case!
I didn’t fully understand what was going on in ClassExistenceResource::isFresh() ☺️

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

No branches or pull requests

2 participants