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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC