Skip to content
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

Don't require a forward slash for exception example #697

Merged
merged 3 commits into from Dec 8, 2015

Conversation

michaelcullum
Copy link
Member

Clarify that forward slash is not required.

@michaelcullum
Copy link
Member Author

@samdark @KorvinSzanto Merge ASAP please

@KorvinSzanto
Copy link
Contributor

I'm not sure that this resolves the point brought up on this list, why are we disallowing use statements for classes in the root namespace? https://3v4l.org/QSnaf

@GrahamCampbell
Copy link
Contributor

I think this example is meant to be when you're not in a namespace.

@michaelcullum
Copy link
Member Author

Indeed and it was due to comments of people saying they refuse to always use \Exception when they don't need to when actually the PSR never required the forward slash, it just disallowed the import.

use Exception; throw new Exception(); is riddled with redundant/dead code and doesn't help clarify understanding at all, in fact it makes it possibly decreases readability as you have to check the two places whereas throw new \Exception(); is so much easier to understand.

@KorvinSzanto
Copy link
Contributor

I'm not sure where I stand on the issue, it sounds a little heavy handed to me tbh. I just wanted to make sure we're really addressing the issue.

…sr-12

* 'master' of github.com:php-fig/fig-standards: (21 commits)
  Switched from specifying HTML to markup in general.
  Update the status of PSR-6
  Update CONTRIBUTING.md
  Update Slovenian translation according to php-fig/fig-standards@0a26e50
  Errata: StreamableInterface should be StreamInterface
  Corrigindo um erro de grafia
  Fix and improve PSR-4
  add PSR-4 translate
  optimize PSR-3
  optimize PSR-2
  optimize PSR-1
  optimize PSR-0
  optimize PSR-3
  修复括号和花括号问题. thx deloz!
  PSR-2 部分修改
  PSR-1 部分修正
  PSR-0 部分修正
  fix 4.3自成一行的问题 thx WangTaizhou
  Fix url and add PSR-2 and PSR-3
  tranlsate PSR-1
  ...
@michaelcullum
Copy link
Member Author

I've added a small clarification on here too. I didn't mean to add two things to the PR but oh well.

It's a common question and certainly within scope. Also most projects don't import root classes anyway.

@simensen
Copy link
Contributor

simensen commented Dec 8, 2015

Also most projects don't import root classes anyway.

I think this would be a case where it would actually make sense to do a survey. :) I don't know that I've seen consistency here anywhere and honestly I'm not sure that it matters too much.

For me, personally, I'd prefer people always use things and never have a leading \ anywhere for the sake of consistency.

Requiring me to always throw \RuntimeException or worse yet extend \RuntimeException is probably going to get a "PSR-12 (without requiring the leading \ for root classes)" label.

@KorvinSzanto
Copy link
Contributor

@simensen I agree. I'm not sure we need to make a judgement on this at all.

@markstory
Copy link

@simensen I also think having explicit use gives code more consistency and makes the imports in any given file simpler to follow.

Exempting root classes from use means the recommended standards are more complex as documenting when to use use is required.

@pmjones
Copy link
Contributor

pmjones commented Dec 8, 2015

@simensen Is exactly right -- this is not a PHP-7-specific requirement, and as such is amenable to survey.

@judgej
Copy link
Contributor

judgej commented Dec 8, 2015

Personally I import any namespaces are are not in the classes namespace. That way you can see right at the top what namespaces that class requires. That helps with portability (assuming you haven't got an IDE that does all that grunt work for you). This includes \Exception, and project aliases such as Laravel's \Log, \Input etc.

Also - can we stop talking about forward slashes.

  • / is a forward slash. It slants forwards in the direction of the text flow, as if pulled down by gravity.
  • \ is a backward slash, as used in namespaces and by DOS because "it ain't Unix".

@judgej
Copy link
Contributor

judgej commented Dec 8, 2015

When wishing to declare strict types in files containing markup outside PHP opening and closing tags MUST, on the first line, include an opening php tag, the strict types declaration and closing tag.

IMO this statement reads more like a work instruction, telling you what to do. It should just describe the end result, what the relationships are between constructs in the code. TBH, I can't even follow what this sentence is saying anyway - it is just confusing even after reading five times. Can it be split up into smaller chunks?

samdark added a commit that referenced this pull request Dec 8, 2015
Don't require a forward slash for exception example
@samdark samdark merged commit 9ea6b8e into php-fig:master Dec 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants