Git Product home page Git Product logo

clearphp's People

Contributors

aleksandrzen avatar bc-bfenton avatar cxbig avatar david-adam avatar derickr avatar dragonmantank avatar dseguy avatar garyjones avatar gmillsap avatar guillaumedievart avatar joanhey avatar johnnypeck avatar kilya11 avatar lamosty avatar markvaughn avatar martijnbleyen avatar meadsteve avatar mozmorris avatar ptondereau avatar rayne avatar tw2113 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clearphp's Issues

Do Not Include Closing PHP Tag In Example Code

We shouldn't encourage people to include a closing php by including it in the examples. This is because if someone writes a php class and then puts a new line character after the closing tag, php will send the response - not the desired behaviour at all!

Whitespace

Currently are all examples, pattern without space between brackets and var.
I think is also a good practice to write readable code.
Maybe I would check all examples for this and send a pull request with the changes - if you like it?

Example:

if (!$foo) {

much better

if ( ! $foo ) {

Also I would add a chapter about space, whitespace in code for better legibility, if you like?

One Tool

Is there one tool (maybe tools) that detects all your /rules?

no-dangling-commas

This is just bad advice.

1.) Indentation here is messed up.

$array = array('a', 
                  'b',
                 );
$array2 = ['c', 
             'd',
            ];

What is going on there? :)

2.) You have a copy paste error in The following pattern is considered legit:

$array = array('a', 
                  'b'
                 );

$array2 = ['c', 'd', ];

I guess that $array2 was supposed to have the , removed?

Either way, trailing commas on multi-line array definitions are awesome. They are also supported in pretty much every language I've used, but are banned in JSON.

They are a style guide choice for sure, but a) they don't hurt at all, and b) they reduce friction and potential conflicts in diffs. I've seen a LOT of conflicts caused by just this, and since asking developers on various teams to use trailing diffs those problems have gone away.

I'd like to see this one deleted entirely.

avoid-those-slow-functions has some bad replacements

How should someone e.g. remove in_array() with isset() when the first function operates on values, while the other could only check for a key. You might advice someone trying to use the isset(), but it's not really a possible replacement. Same is true of diff/intersect on arrays.

Replacing array_walk() and array_map() with a foreach-by-reference could cause some side effects as mentioned in the PHP Pitfalls document you linked to. Although the foreach-by-reference is a lot faster, the usage of the other functions is necessary if you use clean and readable functional programming techniques.

no-double-quote

While you have linked to Nikita's article Disproving the Single Quotes Performance Myth, your advice is still incredibly generalized and not entirely accurate.

I wrote this up on PHP The Right Way: Strings

Scroll down to this bit:

Which is quicker?
There is a myth floating around that single quote strings are fractionally quicker than double quote strings. This is fundamentally not true.

If you are defining a single string and not trying to concatenate values or anything complicated, then either a single or double quoted string will be entirely identical. Neither are quicker.

If you are concatenating multiple strings of any type, or interpolate values into a double quoted string, then the results can vary. If you are working with a small number of values, concatenation is minutely faster. With a lot of values, interpolating is minutely faster.

Regardless of what you are doing with strings, none of the types will ever have any noticeable impact on your application. Trying to rewrite code to use one or the other is always an exercise in futility, so avoid this micro- optimization unless you really understand the meaning and impact of the differences.

no-letter-logical exemple is wrong

In the result $e is false, $f is true.
But it's the opposite:

$ php -r '$e = false || true; var_dump($e);'
bool(true)
$ php -r '$f = false or true; var_dump($f);'
bool(false)

Avoid direct include or require in spl_autoload_register

In https://github.com/dseguy/clearPHP/blob/master/rules/use-smart-autoload.md example:

function my_autoloader($class) {
include 'classes/' . $class . '.class.php';
}

For every include that fail, will generate a warning and increase your log. If you have 4 functions (methods,..) registered using include directly, will create 4 warnings for every request.

It is worse with require, that create a fatal error and stop the execution.

It 's a shame than spl_autoload_register don't work like include_path, that try every path and show the error if all fail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.