Bug #17969: Immediately getting an array element fails with a function

From: Date: Tue, 25 Jun 2002 13:31:05 +0000
Subject: Bug #17969: Immediately getting an array element fails with a function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-12040@lists.php.net to get a copy of this message
From: atalabac@pop500.gsfc.nasa.gov Operating system: Windows 2000 PHP version: 4.2.1 PHP Bug Type: Unknown/Other Function Bug description: Immediately getting an array element fails with a function I have this script: <? // Load configuration @((int)require('config.php')) or die('!Unable to load server configuration file.'); // Connect to db $dbhandle = mysql_connect($dbserver, $dbuser, $dbpass) or die('!Unable to connect to MySQL server.'); mysql_select_db($dbname) or die('!Unable to select Garnet database.'); $variable = $_GET['variable']; $result = mysql_query("SELECT value FROM settings WHERE variable=$variable"); if (!$result) { echo '!Failed to get variable value'; } else { echo mysql_fetch_row($result)[0]; } mysql_close($dbhandle); ?> It appears to work perfectly fine except for line 17: "echo mysql_fetch_row($result)[0];". In every other language I've used this is perfectly acceptable: return the first element of the array returned by mysql_fetch_row($result). However I get this error: Parse error: parse error, unexpected '[', expecting ',' or ';' in page.php on line 17 Is the only workaround to do this? $s = mysql_fetch_row($result); echo $s[0]; -- Edit bug report at http://bugs.php.net/?id=17969&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=17969&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=17969&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=17969&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=17969&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=17969&r=support Expected behavior: http://bugs.php.net/fix.php?id=17969&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=17969&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=17969&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=17969&r=globals

« previous php.bugs (#12040) next »