Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Routing] Throw exception when PHP start tag is missing#18869

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@wouterj
Copy link
Member

QA
Branch?master (?)
Bug fix?yes
New feature?no
BC breaks?yes
Deprecations?no
Tests pass?yes
Fixed ticketssymfony/symfony-docs#6116 (and many more)
LicenseMIT
Doc PR-

The Problem

In the documentation, we never use the PHP start tag. However, in the first tutorials, people simply copy/past the code examples, save the file and expect things to work. They seem to often forget to add the PHP start tag.

Without start tag, the annotation file loader simply skips the file without providing any reason why. As a big framework is quite overwhelming, simple things like this are completely forgotten.

The Fix

If a*.php file only consists ofT_INLINE_HTML, it means there is no<?php start tag. In this case, instead of skipping the file, an exception is throwed with a possible fix.

BC Break?

As the file loader is only executed for*.php files, I think the BC break is minimal, but it is possible that people have applications with*.php fileswithout a start tag. If this file lives in a routing loaded directory (e.g. when doing@AppBundle/Controller), it would now result in an exception.

I think this BC break is minimal and can be ignored. If you don't agree, we can add a little str match to check ifclass ... { exists. If that's the case, I think it's safe to say that it was meant to be a PHP file.

Bug or Feature?

I don't know if this is considered a bug or a feature, so I submitted it as a feature.

javiereguiluz, Nicofuma, and Simperfit reacted with thumbs up emoji
@wouterjwouterj changed the titleThrow exception when PHP start tag is missing[Routing] Throw exception when PHP start tag is missingMay 25, 2016
@javiereguiluz
Copy link
Member

A minor comment to reviewers: missing the opening PHP tag may seem like a stupid problem ... but please trust us when we say that we have received lots of reports about this error. We really need to fix this issue one way or another. Thank you!

@OskarStark
Copy link
Contributor

PR looks appropriate to me 👍 , but yes it is a BC break

$namespace =false;
$tokens =token_get_all(file_get_contents($file));

if (1 ===count($tokens) &&T_INLINE_HTML ===$tokens[0][0]) {

Choose a reason for hiding this comment

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

won't warn for code looking like

foo<?phpbar

intended?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think so. We're catching the case of forgetting the open PHP tag here, not whether the PHP tag is the first token in the file.

Copy link
Member

Choose a reason for hiding this comment

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

this needs to account for the fact that tokens are not always arrays

Choose a reason for hiding this comment

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

the first one is always an array :)

Copy link
MemberAuthor

@wouterjwouterjMay 25, 2016
edited
Loading

Choose a reason for hiding this comment

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

In this case, as it's the first item, only two options are available: inline HTML or PHP start tag. These both are arrays, so we don't have to worry about it.

Btw, I just discovered that we can simplify this by only doingcount($tokens) === 1, just<?php returns T_INLINE_HTML with<?php as value.

Copy link
Member

Choose a reason for hiding this comment

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

this is because the PHP start tag is either<?php or<?phpEOL (with whatever supported EOL char)

@linaori
Copy link
Contributor

Besides of being a silly check forgotten, it's also quite embarrassing how you miss this error when helping someone. As more experienced phper, I kind of expect to see an open tag and if not present-make the basic assumption people simply left it out of the example. 👍 for this.

@nicolas-grekas
Copy link
Member

rebase needed

@wouterjwouterjforce-pushed therouting_loader_without_php_start_tag branch from556cfa1 to1e765c8CompareJune 7, 2016 07:45
@wouterj
Copy link
MemberAuthor

Status: Needs Review

@nicolas-grekas
Copy link
Member

👍

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedJun 7, 2016
edited
Loading

Personally I'd be OK to merge this into 2.7 btw. The potential BC break is not more allowed on master than on 2.7. Thus if we're ok to consider its potentiality is near to zero, then 2.7 should be the target.

@fabpot
Copy link
Member

@nicolas-grekas I don't agree. Introducing a potential BC break in master is ok and can be documented. Introducing a small BC break in a patch version is a no-go.

nicolas-grekas reacted with thumbs up emoji

@dunglas
Copy link
Member

👍

@fabpot
Copy link
Member

Thank you@wouterj.

@fabpotfabpot merged commit1e765c8 intosymfony:masterJun 12, 2016
fabpot added a commit that referenced this pull requestJun 12, 2016
…g (WouterJ)This PR was merged into the 3.2-dev branch.Discussion----------[Routing] Throw exception when PHP start tag is missing| Q             | A| ------------- | ---| Branch?       | master (?)| Bug fix?      | yes| New feature?  | no| BC breaks?    | yes| Deprecations? | no| Tests pass?   | yes| Fixed tickets |symfony/symfony-docs#6116 (and many more)| License       | MIT| Doc PR        | -The Problem---In the documentation, we never use the PHP start tag. However, in the first tutorials, people simply copy/past the code examples, save the file and expect things to work. They seem to often forget to add the PHP start tag.Without start tag, the annotation file loader simply skips the file without providing any reason why. As a big framework is quite overwhelming, simple things like this are completely forgotten.The Fix---If a `*.php` file only consists of `T_INLINE_HTML`, it means there is no `<?php` start tag. In this case, instead of skipping the file, an exception is throwed with a possible fix.BC Break?---As the file loader is only executed for `*.php` files, I think the BC break is minimal, but it is possible that people have applications with `*.php` files *without* a start tag. If this file lives in a routing loaded directory (e.g. when doing `@AppBundle/Controller`), it would now result in an exception.I think this BC break is minimal and can be ignored. If you don't agree, we can add a little str match to check if `class ... {` exists. If that's the case, I think it's safe to say that it was meant to be a PHP file.Bug or Feature?---I don't know if this is considered a bug or a feature, so I submitted it as a feature.Commits-------1e765c8 Throw exception when PHP start tag is missing
@wouterjwouterj deleted the routing_loader_without_php_start_tag branchJune 12, 2016 08:35
@fabpotfabpot mentioned this pull requestOct 27, 2016
fabpot added a commit that referenced this pull requestMar 2, 2017
…om annotations (jakzal)This PR was merged into the 2.7 branch.Discussion----------[Routing] Ignore hidden directories when loading routes from annotations| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#21497| License       | MIT| Doc PR        | -The problem surfaced after implementing#18869. Therefore it doesn't exist on 2.7, but I'd still merge it there to avoid conflicts when merging between branches. Without this fix, the oldest branch the added test will fail is 3.2.Commits-------ce9df02 [Routing] Ignore hidden directories when loading routes from annotations
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

9 participants

@wouterj@javiereguiluz@OskarStark@linaori@nicolas-grekas@fabpot@dunglas@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp