php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #366 Bug with Variable variable arrays
Submitted: 1998-05-08 15:57 UTC Modified: 1998-05-08 16:16 UTC
From: jwalsh at verio dot net Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0 Latest CVS OS: Solaris 2.5x
Private report: No CVE-ID: None
 [1998-05-08 15:57 UTC] jwalsh at verio dot net
The reproducible error

Parse error</b>:  parse error, expecting `'}'' in <b>/home/virtual/celsoc/db/list.php3</b> on line <b>34</b><br>

occurs with the following code segment.  It seems to be a problem with variable variables and arrays.

<SCRIPT LANGUAGE="PHP">
require("./inc/globalsettings.inc");

// HELP WANTED LISTING
if ($cmd == "wantedpost") {
        $msg = "Employment Openings";
        $dbTable = "HelpWanted";

        // FIRST TWO ITEM VALS PASSED FROM PREVIOUS PAGE
        $item = array("Region","Type","FirmName","Location","ShortDescrip");
        $query = "SELECT _rowid,";

// HELP AVAILABLE LISTING
} elseif ($cmd = "availablepost") {
        $msg = "Personnel Available";
        $dbTable = "HelpAvailable";

        // FIRST TWO ITEM VALS PASSED FROM PREVIOUS PAGE
        $item = array("Region","License","Name","Location","ShortDescrip");
        $query = "SELECT _rowid, ContactFirst || || ContactLast AS ";
}
$query .= "$item[0],$item[1],$item[2],$item[3],$item[4] ";
$query .= "FROM $dbTable ";

// MAX NUMBER OF ITEMS RETRIEVED AT ONCE
$startval = intval($next);
$maxquery = 15;

// BUILDING QUERY
for ($i=0, $qcount=0; $i<4; $i) {
        if (strlen(${$item[$i]}) > 0) {
                if ($qcount > 0) $query .= "AND ";
                else $query .= "WHERE ";
                if ($i == 3) $query .= "$item[3] LIKE '%${$item[3]}%' ";
                else $query .= "$item[$i]='${$item[$i]}' ";
        $qcount++;
        }
}
$query .= "ORDER BY $item[0] LIMIT $startval,$maxquery";

// CONNECT TO DB AND PERFORM QUERY
echo $query;
mysql_connect($dbHost,$dbUser,$dbPwd);
$result = mysql($dbName,$query);
$num = mysql_NumRows($result);
</SCRIPT>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-05-08 16:16 UTC] zeev
These variables are not supported within encapsulated
strings.  Variable expansion inside encapsulated strings
is extremely limited in version 3.0, and as a rule of the
thumb, only very simple variables are recognized.

This will only be addressed in version 3.1.  In the
meantime, use the concatenation operator instead, e.g.

"_text_".${...}."_text_"


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC