#32413 [NEW]: Array accessed method
| From: | barnaby dot scott at uk dot wanadoo dot com | Date: | Tue, 22 Mar 2005 16:34:33 +0000 |
| Subject: | #32413 [NEW]: Array accessed method | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-76733@lists.php.net to get a copy of this message | ||
From: barnaby dot scott at uk dot wanadoo dot com
Operating system: N/A
PHP version: Irrelevant
PHP Bug Type: Feature/Change Request
Bug description: Array accessed method
Description:
------------
I was just playing about with the array functions, and I feel that there
is a missing behaviour. It would be a sort of shortcut to a for loop, the
way that array_walk is a shortcut to looping through the array and
performing an action on each element. My proposed shortcut function would
replace this sort of code:
for ( $i=0; $i < count( $array ); $i++ ) {
$tmp = $array[ $i ];
$tmp->someFunc();
}
With something like this:
$array->someFunc();
Essentially treating the array as an object, obviously all of the elements
in the array would have to implement the someFunc method, but then that
could be taken care of with some type hinting. It's really just something
that I thought would make my code a lot cleaner.
Cheers
Barney
Reproduce code:
---------------
(The sort of syntax that i was thinking of)
interface ExampleInt {
public function printVar();
}
class Example implements ExampleInt {
private $aVar;
public function __construct( $val ) {
$this->aVar = $val;
}
public function printVar() {
print $this->aVar . '<br>';
}
}
$exArray = ExampleInt array();
$exArray[] = new Example( 'one' );
$exArray[] = new Example( 'two' );
$exArray[] = new Example( 'three' );
$exArray[] = new Example( 'four' );
$exArray[] = new Example( 'five' );
$exArray->printVar();
Expected result:
----------------
one
two
three
four
five
--
Edit bug report at http://bugs.php.net/?id=32413&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32413&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32413&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32413&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32413&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32413&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32413&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32413&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32413&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32413&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32413&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=32413&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=32413&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32413&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32413&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32413&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32413&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32413&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32413&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32413&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32413&r=mysqlcfg