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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 25 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 17:01:30 2024 UTC