Referencing?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Referencing?

Post 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)
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

are startElement and open_tag a part of the same class? if so you don't need to use the global statement.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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..:( :( :(
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

[edit]sorry this post was pointless[/edit]
Last edited by hob_goblin on Sun Oct 06, 2002 12:57 am, edited 1 time in total.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

thats a stumper. i honestly have no clue
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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?
Post Reply