10000 Fix twig_test_empty and twig_length_filter to not trigger autoloading by enumag · Pull Request #2438 · twigphp/Twig · GitHub
[go: up one dir, main page]

Skip to content

Fix twig_test_empty and twig_length_filter to not trigger autoloading #2438

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
wants to merge 1 commit into from

Conversation

enumag
Copy link
@enumag enumag commented Apr 6, 2017

Introduced in #2420, partially fixed in #2433.

cc @mpdude

Also because of this I found another bug in both Symfony and Composer - autoloading fails for an empty string. I'll send pull requests to both shortly.

@@ -1241,7 +1241,7 @@ function twig_test_empty($value)
return 0 == count($value);
}

if (method_exists($value, '__toString')) {
if (is_object($value) && method_exists($value, '__toString')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be optimized, as the is_object test is now always done there is not point for the test at line 1280 (return '' === $value || false === $value || null === $value || array() === $value;) if is_object returned true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like this?

if (is_object($value)) {
    if (method_exists($value, '__toString')) {
        return '' === (string) $value;
    } else {
        return false;
    }
}

return '' === $value || false === $value || null === $value || array() === $value;

Should I use ternary operator?

if (is_object($value)) {
    return method_exists($value, '__toString') ? '' === (string) $value : false;
}

return '' === $value || false === $value || null === $value || array() === $value;

@mpdude
Copy link
Contributor
mpdude commented Apr 6, 2017

What do you mean with "partially fixed"? Isn't this change exactly the same as in #2433?

Note that #2433 was against 1.x which hasn't yet been merged into 2.x.

@enumag
Copy link
Author
enumag commented Apr 6, 2017

@mpdude Right... twig_length_filter doesn't need to be changed because of is_scalar check. So the only thing left is the optimization that @SpacePossum suggested.

@SpacePossum
Copy link
Contributor

the optimize might not be worth a PR I guess

@enumag
Copy link
Author
enumag commented Apr 6, 2017

Alright. In that case I'll just wait for the 1.x branch to be merged into 2.x. Thank you both.

@enumag enumag closed this Apr 6, 2017
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Apr 7, 2017
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #22307).

Discussion
----------

[Debug] Fix php notice

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Of course autoloading of an empty string should not actually happen (fixed that in twigphp/Twig#2438) but if it does happen it should not throw a php notice.

```
Notice: Uninitialized string offset 0
```

Commits
-------

e333a1a [Debug] Fix php notice
symfony-splitter pushed a commit to symfony/debug that referenced this pull request Apr 7, 2017
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #22307).

Discussion
----------

[Debug] Fix php notice

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Of course autoloading of an empty string should not actually happen (fixed that in twigphp/Twig#2438) but if it does happen it should not throw a php notice.

```
Notice: Uninitialized string offset 0
```

Commits
-------

e333a1a [Debug] Fix php notice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0