Page 1 of 1

Referencing?

Posted: Sat Oct 05, 2002 5:07 pm
by hob_goblin
Okay here is my problem:

I have an array that needs to reference a variable that does not exist YET, but when the array is called from a function, i want it to be in use...

so something like:

Code: Select all

<?

$array = array(
     "foo" => "Foo",
     "bar" => "Some text" . &$bar . " Some more text"
     );

$bar = "HERE WE Go.."

function thing($bar)&#123;
     global $array;
     echo $array&#1111;'bar'];
     &#125;

?>
i want it to print out

Some textHERE WE Go.. Some more text

im doing this in OOP, and it's giving me a parse error, but i thought that was the only way i could reference it?

if you need the exact code to be posted i can do that but that was the main idea

(ps, its XML handling of attributes)

Posted: Sat Oct 05, 2002 6:20 pm
by mydimension
seeing the code would be helpful casue the context could make all the difference. i had to do something similar to this where i had my constructor which used a method to connect to a database in order to process the users cookies regardless of whether or not i was printing a header.

confusing? thought so. the point is it required me to think farther outside the box than i was used to.

Posted: Sat Oct 05, 2002 8:22 pm
by hob_goblin

Code: Select all

$this->open_tag = array(
		"TAGBOARD" => "\n<!-- start tagboard, made by dan - ice-on-fire.net -->\n",
		"TAG" => "<!-- " . &$attrs&#1111;'ID'] . " -->",
		"AUTH" => "<b>",
		"WEBSITE" => "<a href="",
		"COMMENT" => "<!-- start comment -->"
		);

Code: Select all

function startElement($parser, $name, $attrs) &#123;
            global $open_tag;
            if ($format = $this->open_tag&#1111;$name]) &#123;
            $this->html .= $format; 
		&#125;
    &#125;
if i put in a print_r($attrs) right after global $open_tag it prints out what i need, so i know it is there.

Posted: Sat Oct 05, 2002 9:27 pm
by mydimension
are startElement and open_tag a part of the same class? if so you don't need to use the global statement.

Posted: Sat Oct 05, 2002 9:32 pm
by hob_goblin
mydimension wrote:are startElement and open_tag a part of the same class? if so you don't need to use the global statement.
true, but that didn't answer my question..:( :( :(

Posted: Sat Oct 05, 2002 9:40 pm
by hob_goblin
[edit]sorry this post was pointless[/edit]

Posted: Sat Oct 05, 2002 10:41 pm
by mydimension
thats a stumper. i honestly have no clue

Posted: Sun Oct 06, 2002 12:56 am
by hob_goblin
it seems that i can reference a variable, even from an array, but i can only have the reference in it...

i can't do anything like:

Code: Select all

$foo = "before " . &$middle . " after";
any ideas?