Questions tagged [psr-1]

PSR-1 is a PHP Standards Recommendation describing PHP's Basic Coding Standard.

PSR-1 is a Standards Recommendation describing PHP's Basic Coding Standard.

36 questions
765
votes
9 answers

PHP | define() vs. const

In PHP, you can declare constants in two ways: With define keyword define('FOO', 1); Using const keyword const FOO = 1; What are the main differences between those two? When and why should you use one and when use the other?
danjarvis
  • 10,040
  • 3
  • 22
  • 21
46
votes
5 answers

What is the difference between StudlyCaps and camelCase?

PSR suggests, method names MUST be declared in camelCase and class names MUST be declared in StudlyCaps.
kta
  • 19,412
  • 7
  • 65
  • 47
13
votes
5 answers

Are parentheses required in PSR-2 PHP ternary syntax?

Question: are parentheses required in PSR-2 PHP ternary syntax? Looking for which (if either) of the following ternary statement's syntax is compliant with PSR-2 - I also need to be pointed to documentation or some authority link: $error =…
Tyler Wall
  • 3,747
  • 7
  • 37
  • 52
7
votes
2 answers

Writing output in a function of a class is what I should not do?

Lately I'm trying to adapt to the PSR standard. On the PSR-1 document it is stated that: Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but…
Qualphey
  • 1,244
  • 1
  • 19
  • 44
5
votes
2 answers

php codesniffer returns nothing ... is my code in standard?

I have a laravel application (created with composer) that I am trying to ensure meets PHP coding standards (level PSR-1). I run: $ phpcs --standard=PSR1 my_app/ And within a few seconds it returns with just a new, empty, ready-to-go command…
Laura_E
  • 169
  • 1
  • 10
4
votes
2 answers

PSR-1: 2.3. Side Effects: variable inside config file

PSR-1 includes recommendation 2.3. Side Effects: A file SHOULD declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it SHOULD execute logic with side effects, but SHOULD NOT do both. Consider this example…
Fabien Snauwaert
  • 4,995
  • 5
  • 52
  • 70
4
votes
2 answers

PhpStorm enforcing PSR-2 on a subset of files

I want my IDE (PhpStorm) to enforce PSR-2 compatible formatting on all of own files. Occasionally however, I have to submit patches on legacy code where I only want to commit functional changes, not changes in code style. How can I enforce PSR-2…
ooxi
  • 3,159
  • 2
  • 28
  • 41
4
votes
2 answers

PSR-2. When to capitalize directories?

As I understood according to PSR-2 standard we should capitalize directory names which contain classes. But how to do if the directory also contains some other files, for example styles and scripts? Say I have a plugin directory, each plugin can…
ymakux
  • 3,415
  • 1
  • 34
  • 43
4
votes
2 answers

Namespace entries in PSR-1 standard?

I am looking for the correct way (if either is correct please let me know) to write namespaces in PHP classes that follow PSR-1 standard. I looked around but didn't see anything specific. Is the correct way to use Namespace Foo\Bar; or is it…
ehime
  • 8,025
  • 14
  • 51
  • 110
3
votes
1 answer

What is the PSR-1 Compliant Alternative to Using ini_set()?

I am in the process of making my code base PSR-2 compliant (and therefore PSR-1 compliant) and I have come across the following code: public function init() { parent::init(); // Allow A Larger PHP Memory Limit For This Script …
Joe Harvey
  • 193
  • 2
  • 7
3
votes
1 answer

Where in the PSR standards does it say to not have the variable name after the type declaration?

Can anyone advise where in the PSR standards docs it documents that there should be nothing after the variable type in class member variables? I used PHP CodeStyle Fixer by doing the following: php-cs-fixer fix MyConsoleCommand.php ...and it removed…
crmpicco
  • 16,605
  • 26
  • 134
  • 210
3
votes
2 answers

Which version of PSR is valid?

Maybe I don't understand fully. I read that PSR is PHP Standard Recommendation, but there are several version of PSR, For Example autoloader use PSR-4 instead Basic Coding Standard use PSR-1 I have to follow a specific PSR version Or I have to…
monkeyUser
  • 4,301
  • 7
  • 46
  • 95
2
votes
1 answer

is creating an instance of a class considered as side effect or declaration in PHP Standards Recommendations?

is creating an instance of class considered as side effect or declaration? how it is considered in PHP recommendation standards.
2
votes
1 answer

Is using alternative PHP syntax for control structures PSR compliant? (when mixed with HTML)

I have looked through the PHP-Fig website for any PSR related to alternative PHP syntax for control structures but failed to find anything about it. The alternative syntax is this for example:

block…

Theo
  • 2,262
  • 3
  • 23
  • 49
2
votes
0 answers

Resolve a PHPCS error in a Laravel migration file

In all my laravel migrations I want to use PSR2, but I getting a warning. use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; class CreatePlayersTable extends Migration { // migration } The…
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
1
2 3