|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17969 Immediately getting an array element fails with a function
Submitted: 2002-06-25 09:31 UTC Modified: 2002-06-25 10:26 UTC
From: atalabac at pop500 dot gsfc dot nasa dot gov Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.1 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: atalabac at pop500 dot gsfc dot nasa dot gov
New email:
PHP Version: OS:


 [2002-06-25 09:31 UTC] atalabac at pop500 dot gsfc dot nasa dot gov
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';
	echo mysql_fetch_row($result)[0];


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];


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-25 10:26 UTC]
this has been requested more than once; I wrote one of the feature requests;
and the outcome was that PHP won't support this syntax.


 [2002-06-25 10:26 UTC]
Expected behaviour. 
There was a feature request about this but IIRC this won't be changed.
Not a bug -> bogus.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 02:03:37 2021 UTC