Posted on Tue 17 May 2011

wtf php

Here are some things that I hate about PHP:

Non-default arguments are allowed after default arguments, but there’s no way to use them.

<?php

 function printabc($a, $b="2", $c) {
     print_r(array('a'=>$a, 'b'=>$b, 'c'=>$c));
 }

 printabc(1,2,3); // normal case

 printabc(4);  // a=>4, b=>2, c=>null; throws warning

 printabc(5,6); // ambiguous call! results in a=>5, b=>6, c=>null; throws warning

/*
 Valid syntax, since assignments return values
Won't do what it looks like, though!
*/
 printabc(7, $c=9, $b=8); // a=>7, b=>9, c=>8

 printabc(1, 2, 3, 4, 5, 6, 7, 8); // No warnings or notices for too many arguments

I’ve also learned that unquoted single word strings are allowed.

<?php

"hello" == hello; //true
echo thisisaword;

This obviously can cause really confusing errors when you forget the dollar sign on your variables. For example:

<?php
$myvar = false;
if( myvar && "a" == 0 ) {
    echo "I'm going to print!";
}

Category: misc

Tags: php, languages that suck, web, programming

Comments: toggle

© Chad Selph. Built using Pelican. Theme by Giulio Fidente on github. .