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

The Big "Why equal doesn't equal" Quiz - PHP Yorkshire

The Big "Why equal doesn't equal" Quiz - PHP Yorkshire

Presented on April 13th 2019 at the PHP Yorkshire conference, York, United Kingdom.
Partial slide deck - the actual quiz will not be made public.
So you think you know PHP? But do you really?

We all compare and test 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 tests and comparisons…. Or are we?

No matter whether you are a beginner or an expert, come and join in the fun for the Big “Why equal doesn’t equal” Quiz, test your knowledge and learn about defensive programming and the quirks of a loose type programming language along the way.

BC Math wrapper: https://gist.github.com/jrfnl/8449978

Juliette Reinders Folmer

April 13, 2019

More Decks by Juliette Reinders Folmer

Other Decks in Programming


  1. @jrf_nl #PHPYorkshire19 Who am I? • Self-employed independent consultant •

    15+ years in IT and software development • Contributor to LimeSurvey, phpBB, WordPress, AdoDB, PHP_CodeSniffer and more
  2. @jrf_nl #PHPYorkshire19 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 ) {}
  3. @jrf_nl #PHPYorkshire19 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() ) {}
  4. @jrf_nl #PHPYorkshire19 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
  5. @jrf_nl #PHPYorkshire19 And remember.... • ... that what you get

    from $_POST/$_GET/database are strings • ... that variable and constant names are case-sensitive by default • ... that switch() does a loose type check • ... that calculations with floats can only be done reliably by casting to string and using bcmath • ... that ctype_ functions are locale() dependent • ... that scalar type declarations will still juggle • ... that strict_types declarations are file-based
  6. Keep in touch! (I’m self-employed, you can hire me ;-)

    ) Rate this talk: joind.in/talk/a76e8 Slides: speakerdeck.com/jrf Contact me: @jrf_nl