Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

PS-3-Standard for best practice #56

Closed
wants to merge 2 commits into from

10 participants

@TiMESPLiNTER

I wrote a new PSR-3 standard to propose the best practice for some php related coding things.

@teplyakoff

May be 'Standard' and 'Best practice' are different things?

@TiMESPLiNTER

Good question... I don't know... for me it's "nice code" because it smplifys code overview and logic. It belongs to the repo admins what they do with my proposal...

@Incognito

This looks out-of-scope.

:-1:

Most of what I can see in all of the PSRs focus on code style guides such as whitespace, and name conventions. This is suggesting a way to use calls and in what order and under what conditions.

I'm unsure what motivation you have for this. It might be because you want only one return part in the code to return output, but my feeling is that's more about architecture of a specific code problem than it is readability and a common coding style between frameworks.

@TiMESPLiNTER

Well I like to know what I expect from a framework which follows the PSR standard also in how the framework sends output to the browser. With this proposal not to use output-buffer and return the output at one specific point in the framework I can be sure nowhere else is output sent to the browser than in one specified method.

@Incognito
@TiMESPLiNTER

Don't know what DI stands for. But OOP definitely yes. I mean a framework with OOP and one in procedural style are heavily compatible. Or you say there are standards for procedural frameworks and for OOP ones. DBAL I'm not sure about. It makes a framework very heavy and complex and in my opinion it's not a must for a framework that it has to provide DBAL out of the box.

I mean for someone who want's to write a simple lightweight framework which probably never uses a DB it's an obstacle. (I know it's most of the time unlikely to not use a DB today.)

@Incognito

I'm all for best practices but again I have to say this sounds out-of-scope for what the PSRs are. You're talking about standards for best practices in an architecture sense, which even if decided upon there's likely to be many cases where we want to break those rules (as happens in standard development). Eventually rather than having all code look the same, we'll end up in a place where we only use one framework one way, or we might end up looking like Java.

My thoughts are that best practices are great, but architecture mandates don't fit into a style guide.

@sebinsua

I agree with @Incognito that this shouldn't be in scope for PSRs. Although it should be pointed out that there doesn't yet exist a bylaw that explains the scope of the PSR system.

I do think it would be a good idea to create something very like the The Zen of Python but for PHP? ...The Zen of PHP. However I think it would better fit in a project such as PHP The Right Way.

@philsturgeon
Owner

I'd say this is massively out of scope and I would like to see it closed.

This is exactly what PHP The Right Way is for.

@dragoonis
Owner

If a second voting member agrees that this should be closed then we can do it.

@deminy

I won't suggest to include this into the PSR system. There are many (built-in) features/extensions in PHP like output control, should we define best practices in PSR for each of those features/extensions?

Besides that, the proposal suggested might be good for most cases, but not always. Suppose a service is going to write 2GB data back to the client (no matter if the data is from a server-side file or a server-side resource), should PHP code hold all data (and concatenate it) into a PHP variable before sending it back? I doubt it.

-1

@philsturgeon
Owner
@jayzeng

These are "perhaps" best practices for your organizations, but I don't see how they can become standard or generate best practices for the community.

@skyzyx

I am a voting member, and I agree that this should be closed.

@dragoonis, go for it.

@dragoonis
Owner

Since multiple people have conveyed that this is clearly out of scope and not suited for the FIG group, it's closed.

Thanks for your efforts @TiMESPLiNTER

@dragoonis dragoonis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 57 additions and 0 deletions.
  1. +57 −0 proposed/PSR-3-best-practice.md
View
57 proposed/PSR-3-best-practice.md
@@ -0,0 +1,57 @@
+The following describes the best practice for a PHP application
+
+Mandatory
+---------
+
+* Don't use Output-Buffers (ob_start()) except to catch output which sends a
+ PHP function (like var_dump()) direct to the browser.
+ Concatinate a string and send the whole content in one step to the browser
+
+Example Implementation
+----------------------
+
+Below is an example script to simply demonstrate how the above
+proposed standards are meant to be. First the bad example afterwards the good
+one.
+```php
+<?php
+
+ob_start(); // or ob_start('gz_handler'); for compression, omit this
+
+echo 'some output';
+
+$testVar = 'hello world';
+
+var_dump($testVar);
+
+ob_end_clean();
+
+echo 'end of site';
+
+/* EOF */
+```
+
+Now the good one:
+
+```php
+<?php
+
+$content = 'some output';
+
+$testVar = 'hello world';
+
+// Here it's okay to use output-buffering, because it's not possible to catch
+// the output of var_dump() otherwise
+ob_start();
+var_dump($testVar);
+$varDump = ob_get_clean(); // Turn off output-buffering here again!
+
+$content .= $varDump;
+
+$content .= 'end of site';
+
+// Finally send to the browser
+echo $content;
+
+/* EOF */
+```
Something went wrong with that request. Please try again.