-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Yaml] don't override internal PHP constants #12372
Conversation
xabbuh
commented
Nov 1, 2014
Q | A |
---|---|
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #11783 |
License | MIT |
Doc PR |
Would it make sense to make similar changes elsewhere in the code where we also override PHP constants? At least where speed is not critical. |
Which parts do you have in mind? |
I think almost all of them: src/Symfony/Bridge/Twig/Extension/CodeExtension.php |
I updated removed other redefinitions of internal PHP constants. However, |
@@ -477,9 +473,14 @@ protected function initializeEscapers() | |||
* @return string the escaped value | |||
*/ | |||
function ($value) use ($that) { | |||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done outside of the function to avoid computing it each time a value is escaped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
👍 (after the escape() method is optimized) |
Thank you @xabbuh. |
This PR was merged into the 2.3 branch. Discussion ---------- [Yaml] don't override internal PHP constants | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11783 | License | MIT | Doc PR | Commits ------- 376cc03 don't override internal PHP constants
@@ -176,7 +172,13 @@ public function formatFile($file, $line, $text = null) | |||
$text = "$text at line $line"; | |||
|
|||
if (false !== $link = $this->getFileLink($file, $line)) { | |||
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset), $text); | |||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth using PHP_VERSION_ID > 50400
instead ? This way, OPCache could optimize it (it will inline the constant value for sure, and it could be smart enough to inline the comparison result as it would compare 2 constants which would then eliminate the useless branch entirely)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that does make sense. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's indeed a good idea (see #12497).
I've just cloned the symfony repository in the hackday of the SymfonyCon and I'm running the tests. I'm getting this strange error:
After having a look at it with @weaverryan we arrived to that issue which is apparently related to the error. This seems to be very related to my specific configuration, I'm using: |
@arnaugm I'll have a look at it. How do you execute the tests? |
Just with
Thanks! |
I have the same error. Same version of OS and PHP. Y tried this
and failing too but this is working
And this working too
I have the error in a lot of test. |
@arnaugm @desarrolla2 Can you both please check if the error disappears when you modify the top of the if (!defined('SYMFONY_TRAIT')) {
if (PHP_VERSION_ID >= 50400) {
define('SYMFONY_TRAIT', T_TRAIT);
} else {
define('SYMFONY_TRAIT', 0);
}
} |
Yes, that makes the test pass. |
…dosten) This PR was squashed before being merged into the 2.6 branch (closes #14515). Discussion ---------- Do not override PHP constants, only use when available | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT In #12372, the override of internal constants has been deleted, but the definition of `JSON_PRETTY_PRINT` if not available is missing in that PR. Commits ------- d5cc056 Do not override PHP constants, only use when available