On Mon, Sep 5, 2016 at 1:13 PM, Nicolas Grekas <nicolas.gre...@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

Reply via email to