php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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';
}
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];

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-25 10:26 UTC] cynic@php.net
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.

closing


 [2002-06-25 10:26 UTC] sander@php.net
Expected behaviour. 
There was a feature request about this but IIRC this won't be changed.
Not a bug -> bogus.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 00:01:23 2019 UTC