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

PS-3-Standard for best practice #56

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions 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 */
```