Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Big "Why equal doesn't equal" Quiz

The Big "Why equal doesn't equal" Quiz

Presented on February 26th 2015 at the Utah PHP User Group, Salt Lake City, Utah, USA.
http://www.uphpu.org/
---------------------------------------------------------------
Partial slide deck - the actual quiz will not be made public.
---------------------------------------------------------------
We all compare data on nearly every other line in our code, be it input validation, an if-statement, a switch or determining what to display and how.
So of course we are all experts on how to do these comparisons…. Or are we?
---------------------------------------------------------------
Links:
http://phpcheatsheets.com/
https://github.com/jrfnl/PHP-cheat-sheet-extended
http://survey.diversitymatters.it/2015

2776198ea9584b6c0d4b494293b8d635?s=128

Juliette Reinders Folmer

February 26, 2015
Tweet

Transcript

  1. The Big “Why equal doesn’t equal” Quiz Presented by: Juliette

    Reinders Folmer @jrf_nl
  2. Who am I? • Self- employed independent consultant • 15+

    years in IT and web development • Contributor to LimeSurvey, phpBB, WordPress, AdoDB and more
  3. None
  4. Now give yourselves a round of applause !!!

  5. Some best practices (1) • Know your variable types and

    how type juggling works ;-) • Always use strict checking unless loose checking will avoid code duplication • Auto-document your code DON’T: if ( strpos( $x, $y ) ) {} DO: if ( strpos( $x, $y ) !== false ) {}
  6. Some best practices (2) • Make it a habit to

    test for type AND for what you want to know • Non-empty string: if ( is_string( $x ) && $x !== ‘’ ) {} • Non-empty array: if ( is_array( $x ) && count( $x ) > 0 ) {} or if ( is_array( $x ) && $x !== array() ) {}
  7. Some best practices (3) • Use function_exists(), method_exists() and extension_loaded()

    to write cross-server code • Be aware of changes across PHP versions • Never be stingy with parentheses () • Avoid $variable contamination • isset() and its brother are your friends
  8. And remember.... • ... that what you get from $_POST/$_GET/database

    are strings • ... that ctype_ functions are locale() dependent • ... that switch() does a loose type check • ... that calculations with floats can only be done reliably by casting to string and using bcmath
  9. Want to know more ?

  10. PHPcheatsheets.com Contributions welcome: https://github.com/jrfnl/PHP-cheat-sheet-extended

  11. One last thing.... I need your help! http://survey.diversitymatters.it/2015 5 minutes

    to answer + spread the word === You're AWESOME !!!
  12. Keep in touch! (I’m self-employed, you can hire me ;-)

    ) Email: juliette@adviesenzo.nl Web: http://www.adviesenzo.nl/ LinkedIn: http://nl.linkedin.com/in/julietterf Twitter: http://twitter.com/jrf_nl GitHub: http://github.com/jrfnl/ Please rate this talk on ... ? Best practice slides: speakerdeck.com/jrf