Re: Missing reflection info about strict types?
| From: | Davey Shafik | Date: | Mon, 05 Sep 2016 20:30:02 +0000 |
| Subject: | Re: Missing reflection info about strict types? | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-95674@lists.php.net to get a copy of this message | ||
On Mon, Sep 5, 2016 at 1:13 PM, Nicolas Grekas <nicolas.grekas@gmail.com>
wrote:
> > Why do you concatenate these files in the first place?
> >
> >
>
> It's not specifically me but Symfony's ClassCollectionLoader::load()
> method, which generates a single file with common classes inlined for
> faster bootstrapping (the perf gain is objectively measurable).
>
> You give this method a list of classes that are always required, and it
> computes all the required parents/interfaces/traits they use, by using
> reflection of course. It turns namespace to the bracketed syntax, orderd
> things as required (parents first), and dumps everything in one php file.
>
> The issue came to our tracker that this process was broken once one wanted
> to inline a strict class there, either directly or indirectly through the
> parent chain.
>
Again, there is not such thing as a strict class. You should be stripping
ALL declare(strict_types=0/1) from the class files, and even if enabled it
at the top of final generated file it wouldn't make any difference _unless_
you're calling the classes IN the generated file. Anything you include it
into will decide for itself whether it is strict or not.
> I worked on the issue and fixed it by replacing the inlining by a "require"
> for now.
>
> Here is the pointer for the fix (then the class & the issue):
> https://github.com/symfony/symfony/pull/19859/files?w=1
I would highly recommend using sprintf() instead of str_replace() to inject
your regex. And again, strip the declare lines completely. Then you can
concat.
https://github.com/symfony/symfony/pull/19859/files?w=1#diff-e37b3a45b919f2dd526570353388e4a5R1
This isn't a class with strict types, it's a file that will enforce strict
types on code that _it_ calls, not code that calls the class defined inside
it.
- Davey