Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27214 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5507 invoked by uid 1010); 29 Dec 2006 21:07:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 5492 invoked from network); 29 Dec 2006 21:07:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Dec 2006 21:07:11 -0000 Authentication-Results: pb1.pair.com header.from=danielc@analysisandsolutions.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danielc@analysisandsolutions.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain analysisandsolutions.com from 166.84.1.74 cause and error) X-PHP-List-Original-Sender: danielc@analysisandsolutions.com X-Host-Fingerprint: 166.84.1.74 mail3.panix.com Received: from [166.84.1.74] ([166.84.1.74:57913] helo=mail3.panix.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 86/19-23744-D7385954 for ; Fri, 29 Dec 2006 16:07:10 -0500 Received: from panix5.panix.com (panix5.panix.com [166.84.1.5]) by mail3.panix.com (Postfix) with ESMTP id AB13413A865 for ; Fri, 29 Dec 2006 16:07:06 -0500 (EST) Received: (from analysis@localhost) by panix5.panix.com (8.11.6p3/8.8.8/PanixN1.1) id kBTL76J12797 for internals@lists.php.net; Fri, 29 Dec 2006 16:07:06 -0500 (EST) Date: Fri, 29 Dec 2006 16:07:06 -0500 To: PHP Internals List Message-ID: <20061229210706.GA14001@panix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.10i Subject: invalid array key/index not generating notices From: danielc@analysisandsolutions.com (Daniel Convissor) Folks: I came across a subtle bug a developer introduced into our application. It took us a month to realize the bug was there because PHP didn't throw a notice. Here is a simplified version of what was happening. // function some_func() {} $a = some_func(); if ($a['do_something'] == true) { // Do it. } some_func() was supposed to return an array. But it was returning void. So $a was NULL. Oops -- we all make mistakes. What's unfortunate is PHP didn't raise a "Notice: Undefined index: do_something" here. It would have saved us some headaches. I'm sure others have run into this as well. The following also doesn't produce a notice: $a = 12; echo $a['k'] I looked through the bugs database and mailing list archive and came up with nothing on this particular issue. But bugs 29271, 30885 and 38165 cover the situation where a key's string is auto-converted to 0: // While this is a behavior we all truly expect: $a = 'value'; echo $a[0] . "\n"; // output: v // Another oddity, but people closing bugs say it's expected: $a = 'value'; echo $a['k'] . "\n"; // output: v This last behavior is counter-intuitive, let alone un-documented. Wondering what the folks here think about this. Thanks, --Dan -- T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y data intensive web and database programming http://www.AnalysisAndSolutions.com/ 4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409