472,960 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 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 1847
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.