Why are PHP function signatures so inconsistent?
Posted
by
Shamim Hafiz
on Programmers
See other posts from Programmers
or by Shamim Hafiz
Published on 2010-12-30T09:29:55Z
Indexed on
2011/12/01
10:22 UTC
Read the original article
Hit count: 405
I was going through some PHP functions and I could not help notice the following:
<?php
function foo(&$var) { }
foo($a); // $a is "created" and assigned to null
$b = array();
foo($b['b']);
var_dump(array_key_exists('b', $b)); // bool(true)
$c = new StdClass;
foo($c->d);
var_dump(property_exists($c, 'd')); // bool(true)
?>
Notice the array_key_exists()
and property_exists()
function.
In the first one, the property name(key for an array) is the first parameter while in the second one it is the second parameter. By intuition, one would expect them to have similar signature. This can lead to confusion and the development time may be wasted by making corrections of this type.
Shouldn't PHP, or any language for that matter, consider making the signatures of related functions consistent?
© Programmers or respective owner