You are here: Global variables « All PHP « IT news, forums, messages
Global variables

Posted by Charles O'Flynn on 09/26/06 19:24

As a complete newcomer (2-3 days) to PHP, although not to programming in
general, I have 'dived in' to start a small project to read and parse an XML
data stream. I have already worked out most of the more specialist aspects
of the job but am now completely stuck on something I would have thought
were simplicity itself...
I need to have a large number of global variables visible inside functions -
it's not possible to pass them into the functions themselves, since although
they are user functions, the parameter type/count is fixed. Reading what
information I can find, I was under the impression that variables declared
at the head of the PHP block as 'global' would be visible inside all
functions. My problem is this: yes, it appears I can assign values to
these global variables inside a function, (I think), but immediately I exit
the function, the data is lost. At first sight, I could be assigning values
to variables with identical names but local scope within the functions, but
when I performed an 'explode()' inside a function, assigning the result to
one of my 'global' variables and then, on exiting the function, tried to
'echo' the result, the result was 'ARRAY' - the original global variable had
presumably been converted, since it started life as a scalar.
I don't really want to go to superglobals unless I have to - can anybody
please tell me where I'm going so obviously wrong and how I can correct it?
This is such a basic problem, I can't help thinking everybody must know the
answer...
Thanks for any help/advice offered.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация