note 61756 added to language.variables.scope
| From: | franp at free dot fr | Date: | Sat, 11 Feb 2006 00:25:24 +0000 |
| Subject: | note 61756 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103482@lists.php.net to get a copy of this message | ||
If you want to access a table row using $GLOBALS, you must do it outside string delimiters or using
curl braces :
$siteParams["siteName"] = "myweb";
function foo() {
$table = $GLOBALS["siteParams"]["siteName"]."articles"; // OK
echo $table; // output "mywebarticles"
$table = "{$GLOBALS["siteParams"]["siteName"]}articles"; // OK
echo $table; // output "mywebarticles"
$table = "$GLOBALS[siteParams][siteName]articles"; // Not OK
echo $table; // output "Array[siteName]article"
$result = mysql_query("UPDATE $table ...");
}
Or use global :
function foo() {
global $siteParams;
$table = "$siteParams[siteName]articles"; // OK
echo $table; // output "mywebarticles"
$result = mysql_query("UPDATE $table ...");
}
----
Server IP: 64.246.30.37
Probable Submitter: 195.154.42.149
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61756
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61756&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61756&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61756&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61756&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61756&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61756&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61756&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61756&report=yes
Search -- http://master.php.net/manage/user-notes.php