note 83711 deleted from control-structures.foreach by danbrown

From: Date: Fri, 24 Jul 2009 15:53:22 +0000
Subject: note 83711 deleted from control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158700@lists.php.net to get a copy of this message
Note Submitter: php_manual at SPAMNONE dot jessemccarthy dot net ---- In PHP 4, foreach is broken when used on an undefined array element (see http://bugs.php.net/bug.php?id=41169 ): <?php $example = array(); foreach ( $example[ 'element' ] as $value ) { } var_dump( $example ); ?> Expected output: array(0) { } Actual output: array(1) { ["element"]=> NULL } I think this is probably the least painful workaround: <?php $example = array(); foreach ( (array) $example[ 'element' ] as $value ) { } var_dump( $example ); ?> Output: array(0) { }

« previous php.notes (#158700) next »