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
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Fri Oct 13, 2006 12:48 pm
I have this code an I'm getting this error:
PHP Parse error: syntax error, unexpected '=', expecting ',' or ';'
Code: Select all
function tag_contents($parser, $data) {
settype($data, "string");
global $new = str_split($data); // This is the line causing the error
}
Any ideas?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Oct 13, 2006 1:02 pm
you cannot assign a global at the same time as assigning it's value. Better yet, avoid globals all together and get rid of the code smell.
Code: Select all
function tag_contents($parser, $data) {
settype($data, "string");
return str_split($data);
}
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Fri Oct 13, 2006 1:03 pm
It has to be done. I need that data outside of that function.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Oct 13, 2006 1:04 pm
So return it like Jcart's version does.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Oct 13, 2006 1:10 pm
I have never been forced into a global variable. If you do what Jcart says, you can just grab the return value and assign it to a variable in the particular scope you need it in...
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Fri Oct 13, 2006 1:13 pm
I'm getting "Undefined variable" when trying to access $data outside of that function.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Oct 13, 2006 1:28 pm
Code: Select all
<?php
function tag_contents($parser, $data) {
settype($data, "string");
return str_split($data);
}
$xyz = tag_contents($p, $d);
echo $xyz;
?>
But I guess you want to use tag_contents() as part of a SAX parser (via xml_set_..._handler).
What do you want to achieve with "globalizing" some of the xml data?
Can you show us more code?
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Fri Oct 13, 2006 6:27 pm
Code: Select all
function tag_contents($parser, $data) {
global $new;
settype($data, "string");
$new = str_split($data);
}
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Oct 13, 2006 7:06 pm
impulse() wrote: I'm getting "Undefined variable" when trying to access $data outside of that function.
How are you accessing it outside that function? Post your function code and sample call to it.