473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

PHP variable "supernaturally set" - how is this possible???

print_r("From index.php 20: $prefix: stateXML = $stateXML<P>");
foreach (array('state', 'country') as $prefix) {
print_r("From index.php 21: stateXML = $stateXML<P>");
${$prefix . 'XML'} = $this->getXML($prefix . '.xml');
}
I have never seen anything like this in my 3+ years of PHP coding!
When I ran this code, I get the following output:

From index.php 20: : stateXML =

From index.php 21: stateXML = state
How on earth did $stateXML get set, there is literally NOTHING that
sets it!!! Here is the method getXML():

function getXML($xmlFileName) { // XML STRING METHOD
global $DOCUMENT_ROOT, $devpath, $basePath;

$path = "$DOCUMENT_ROOT$devpath/image_catalog";

if (!$xmlFileName || !file_exists("$path/xml/$xmlFileName"))
die("$path/xml/$xmlFileName does not exist");
$fileID = @fopen("$path/xml/$xmlFileName", 'r') or
die("$path/xml/$xmlFileName could not be found");
if (!$fileID) return '';
$xmlStuff = fread($fileID, filesize("$path/xml/$xmlFileName"));
fclose($fileID);
return $xmlStuff;
}
Again, how is $stateXML existing when there is clearly NO reason for
it to ever exist??

Help!
Phil
Jul 17 '05 #1
2 1870
Phil Powell wrote:
print_r("From index.php 20: $prefix: stateXML = $stateXML<P>");
foreach (array('state', 'country') as $prefix) {
print_r("From index.php 21: stateXML = $stateXML<P>");
${$prefix . 'XML'} = $this->getXML($prefix . '.xml');
}
I have never seen anything like this in my 3+ years of PHP coding!

When I ran this code, I get the following output:

From index.php 20: : stateXML =

From index.php 21: stateXML = state
How on earth did $stateXML get set, there is literally NOTHING that
sets it!!! Here is the method getXML():

(snip)
Strange coding, in fact! :)
[ Why print_r() where a simple echo (or print()) would do? ]
This line

${$prefix . 'XML'} = $this->getXML($prefix . '.xml');

when $prefix='state' is the same as

${$prefix . 'XML'} = $this->getXML($prefix . '.xml');
${'state' . 'XML'} = $this->getXML('state' . '.xml');
${'stateXML'} = $this->getXML('state.xml');

$stateXML = $this->getXML('state.xml');
but $stateXML doesn't get set *before* it is printed !!!

The first time through the loop it will print a blank $stateXML, and
_after_ that set it to the contents of ".../xml/state.xml"; the second
time through the loop it will print that data and set $countryXML to the
contents of the file ".../xml/country.xml".
read about 'variable variables' @
http://www.php.net/manual/en/languag...s.variable.php
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Pedro Graca <he****@hotpop.com> wrote in message news:<bu************@ID-203069.news.uni-berlin.de>...
Phil Powell wrote:
print_r("From index.php 20: $prefix: stateXML = $stateXML<P>");
foreach (array('state', 'country') as $prefix) {
print_r("From index.php 21: stateXML = $stateXML<P>");
${$prefix . 'XML'} = $this->getXML($prefix . '.xml');
}
I have never seen anything like this in my 3+ years of PHP coding!

When I ran this code, I get the following output:

From index.php 20: : stateXML =

From index.php 21: stateXML = state
How on earth did $stateXML get set, there is literally NOTHING that
sets it!!! Here is the method getXML():

(snip)
Strange coding, in fact! :)
[ Why print_r() where a simple echo (or print()) would do? ]
This line

${$prefix . 'XML'} = $this->getXML($prefix . '.xml');

when $prefix='state' is the same as

${$prefix . 'XML'} = $this->getXML($prefix . '.xml');
${'state' . 'XML'} = $this->getXML('state' . '.xml');
${'stateXML'} = $this->getXML('state.xml');

$stateXML = $this->getXML('state.xml');
but $stateXML doesn't get set *before* it is printed !!!

The first time through the loop it will print a blank $stateXML, and
_after_ that set it to the contents of ".../xml/state.xml"; the second
time through the loop it will print that data and set $countryXML to the
contents of the file ".../xml/country.xml".
read about 'variable variables' @
http://www.php.net/manual/en/languag...s.variable.php

Thanx, however, it still occurs. I traced it to literally occur the
moment I go into the foreach loop *BEFORE* it ever goes to
$this->getXML(). Somehow, for reasons I cannot explain, I found out
that not only is $stateXML existing with the value of 'state', but so
is $state, $xml, $XML, $State, $a, $b, $c, $x, $y, $z, $... literally
every existing combination of valid letters that form a variable all
suddenly not only exist but have a value of 'state'!

Phil
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Erick Bodine | last post by:
I am trying to set a new environment variable on a W2k machine with only partial success. The name("SSID") and value("ASIM") show up correctly in the registry and when I go to "System...
7
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
7
by: deko | last post by:
I'm getting intermittent "Object Invalid or No Longer Set" errors in my Access 2002 mdb. What causes these errors? Has anyone dealt with this before? I can't trace it because it's not easy...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
0
by: Pierson C | last post by:
A quick easy one! I have a custom user control that has an ArrayList property. I create an instance of the user control, assign all of the properties, but when I add the control to the page, my...
1
by: Gregor Horvath | last post by:
Hi, I searched the web and docs but cannot figure out whats wrong with this code: #!/usr/bin/python import Tkinter as Tk class testtk(Tk.Frame):
9
by: axs221 | last post by:
I am trying to move some of our large VBA Access front-end file into ActiveX DLL files. I created two DLL files so far, one was a module that contains code to integrate into the QuickBooks...
10
by: nspader | last post by:
I want to start out saying I am a novice code writer. I am trying to send a report via email based on each supplier. The code below is what I am using. I need to base recordset on Form, report...
1
by: dehboy | last post by:
Here's the deal. I'm trying to write an excel macro in VBA that will take a bunch of data and create a nice bubble chart out of it. First, it checks if the row I'm adding to the chart is the first...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.