Test your variables!
When PHP throws you an error, there is always a reason. My dev box is set up to throw me everything it finds, and as I am working on a code that needs strong optimization, a question crossed my mind. Before I ask the question, here’s the (simplified) error-ing code:
// Function is called many times (~1M)
function doSomething($arrTest) {
$strName = $arrTest[0];
$strType = $arrTest[1];
$strColor = $arrTest[2];
}
$arrTest = array('banana', 'fruit');
doSomething($arrTest); Of course, $arrTest[2] doesn’t exist, and PHP, as friendly as it is, works perfectly, just throwing a notice.