$W = '<img src="'.$Path.'R_Images/Marks/WhiteBall.gif" width="14"
height="14">';
...and can reference this within any PHP code, but I *can't* reference
it from within a PHP function, unless it's been passed as an argument.
I can't find this documented anywhere, but it appears to fit all of the
observations.
If *not* true, can someone tell me how to reference such a string from
within a function *without* passing it as an argument?
Thanks.
John Kopf
Unless you use the global keyword within your function, as in
global $w;
That is correct, and it is intentional. See
http://www.php.net/manual/en/language.variables.scope.php.
You can use the global keyword - but much better is to pass the variable
as an argument to the function.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
look up the global command
> Thanks.
>
> John Kopf
>
"Look up" Where? I used it, and it solved my problems, but where is it
described? Google "global command" or "global" and you get a million
hits, none of which appear to apply, before giving up :>{
John Kopf
You do NOT want to use global, for many reasons. You should pass the
item as a function parameter.
Don't worry about what TNP says - his advice is seldom accurate, and
even more rarely is it good.
well since this is php, how about
google: php global
for me the very first result is the php documentation for it.
In this case it is accurate, and its up to the OP to decide whether its
'good' or not, not you.
Nope, use of globals is bad - in any DECENT programmer's book. For
reasons beyond your understanding, because it requires intelligence.
Now go back to your ditch digging. Here's a tip - the wide end of the
shovel goes in the ground.
IBTD.
<snip strawman argument>
So why, for instance, is $_POST automatically global?
And why, for instance is $_SESSION automatically global?
And why, for instance, should I not make my used-every-bloody-where variable
$database global. Do you expect me to pass the name of my database as a
variable to each and every single function that just might make a call on
that database?
And every DECENT programming language has provision for making certain
variables global. Especially the one I use day to day, C++, although C#
seems to have fucked it up.
Jerry, just because *you* do it that way does not mean that *all* of us must
do it that way as well. If you feel so strongly about the global keyword
then please cite your objection to the people who wrote PHP.
<snip strawman argument>
These have nothing to do with the use of the global keyword. YOU are
making strawman arguments.
> And why, for instance, should I not make my used-every-bloody-where variable
> $database global. Do you expect me to pass the name of my database as a
> variable to each and every single function that just might make a call on
> that database?
>
Yep. The function is now independent of the name of the variable in
rest of the code. You can call the function from different areas of the
code, using different variable names.
For instance - what if you need to open TWO different connections to a
database? Your functions now fail on one of those connections, because
it is more closely tied to the rest of the program than necessary. It
also increases maintenance costs and more potential problems when
modifying the code.
Well written functions are independent of anything in the code other
than what is passed to them. This is true in ANY language supporting
functions.
> And every DECENT programming language has provision for making certain
> variables global. Especially the one I use day to day, C++, although C#
> seems to have fucked it up.
>
Another strawman argument. That does not mean they are good. C has a
"goto" statement, also. But even Kernighan and Ritchie admitted it was
a bad thing.
And if globals are so great, why even have variable scope? Just make
everything global (like COBOL did).
> Jerry, just because *you* do it that way does not mean that *all* of us must
> do it that way as well. If you feel so strongly about the global keyword
> then please cite your objection to the people who wrote PHP.
>
> <snip strawman argument>
>
>
Yet a third strawman argument. This one isn't even worth responding to.
I can't help it if you write terrible code like TNP. But please don't
encourage others to follow your examples.
Stuckly, you are really and truly a fuckwit.
After considerable parsing, it appears that this comment does not
add to the discussion. Go to your room.
bill
Gee, you can't continue a logical discussion so you have to come back
with personal insults.
How like the troll.
You should really read some books on program design. You might learn
something.
Oh dear ooh dear. Why dio the Gods of PHP include it then?
Never mind jerry, its a grown up tool for grown ups and dangerous in
childish hands, so you stick to your gbuns OK and eat your greems and
you might grow up to be a Real Progranmmer yet.
For
> reasons beyond your understanding, because it requires intelligence.
>
> Now go back to your ditch digging. Here's a tip - the wide end of the
> shovel goes in the ground.
Oh dear. You don't dig with shovels, and the narrow end of a spade
called the blade, goes in the ground. The wider put is where your hand go.
Therese a scientific explanation as to why blades are thin and handles
thick, but you wouldn't understand it. It has numbers and formulae in it.
Sigh. Such a waste. Not even fit to dig a ditch.
>
Since this is about php, I would try
google: php global
works for me.
Sorry, I wasn't clear...
Nowhere in the PHP pages I've found, using Google, was there any
reference to "global" - thus, not knowing the word to use, I couldn't
google it.
What I need is a (hopefully, pdf) manual or specification for PHP that I
can download and refer to off-line, and which is complete enough to
actually mention things like "global"...Most just give lists of the
common string functions, with (VERY) simple examples.
John Kopf
Beware however, that any other function in any (included) program file
can so access it.
Which may be a blessing, or a curse, depending..
Sometimes people don't care to do things properly. "Half-assed in half
the time" and all that. That doesn't mean it's a good idea to advise it
or to label it as "good". It's still bad, just expedient.
> Never mind jerry, its a grown up tool for grown ups and dangerous in
> childish hands, so you stick to your gbuns OK and eat your greems and
> you might grow up to be a Real Progranmmer yet.
I hate cleaning up after "Real Programmers". Gimme a well-trained n00b
any day...
> For
>> reasons beyond your understanding, because it requires intelligence.
>>
>> Now go back to your ditch digging. Here's a tip - the wide end of the
>> shovel goes in the ground.
>
> Oh dear. You don't dig with shovels, and the narrow end of a spade
> called the blade, goes in the ground. The wider put is where your hand go.
>
> Therese a scientific explanation as to why blades are thin and handles
> thick, but you wouldn't understand it. It has numbers and formulae in it.
>
> Sigh. Such a waste. Not even fit to dig a ditch.
I admire your use of pedantic irrelevancies, but you can't distract me
or anyone else with them.
--
"This place is evil! We need weapons! Crossbows! Rocket Launchers!
Rent-a-zilla!"
-- L33t Master Largo www.megatokyo.com
Then they aren't real programers are they?
>> For
>>> reasons beyond your understanding, because it requires intelligence.
>>>
>>> Now go back to your ditch digging. Here's a tip - the wide end of the
>>> shovel goes in the ground.
>> Oh dear. You don't dig with shovels, and the narrow end of a spade
>> called the blade, goes in the ground. The wider put is where your hand go.
>>
>> Therese a scientific explanation as to why blades are thin and handles
>> thick, but you wouldn't understand it. It has numbers and formulae in it.
>>
>> Sigh. Such a waste. Not even fit to dig a ditch.
>
> I admire your use of pedantic irrelevancies, but you can't distract me
> or anyone else with them.
>
Global's have their place: That's why they are included.
If you have one and one only master data structure in a program its a
waste of time to keep copying it around and passing it mindlessly down
through one function after another, especially when you can't even get
it permanently altered by any of them unless you return a value all the
way up the nest to set something in it, and then what happens to your
error returns? sure you can pass by reference, but that IS what the
global keyword does *anyway*.
No one is advocating removing local variables from the language: merely
recognising the usefulness of global scopes, and its pitfalls.
PHP has its own global variables built in, for good reasons. You can
extend them as you see fit.
Good program design is not slavishly following rules. Its about
understanding when its actually harder and trickier and more lexically
confusing to to keep to them, than to break them.
: google: php global
: works for me.
Why are my posts turning up in a different thread? I didn't see my
earlier response and thought I had imagined sending it, now I see it here.
Oh well, oddities abound.
"The Problem" is that, breaking "the rules" not only requires good
understanding by the particular programmer writing the code, but
everyone thereafter that's supposed to modify it has to understand the
rules in exactly the same way and get into the head of that particular
programmer in the same kind of way in order to work with the program
code effectively. That's HARD to do, and were more programmers willing
to be less "Real Programmer" hardcore and code very conservatively and
very close to some commonly-accepted best practices, it makes them more
like each other and less of a pain in the ass to get into their heads.
For example, a coworker of mine has a stylistic thing where he loathes
testing complicated conditions. So, before anything that's really
complicated he'll start setting flag variables and things far up in the
code before the condition test, sometimes multiple times changing the
value, or assigning more than one flag at a check, which means every
damn time I want to follow the value of a variable, I end up having to
follow five or six instead, just to see the consequences.
--
1. My Legions of Terror will have helmets with clear plexiglass visors,
not face-concealing ones.
--Peter Anspach's list of things to do as an Evil Overlord
Oh, indeed, but the presence of the Global keyword is a bit of a giveaway..
Unlike C, a global variable is explicitly defined within a function. So
you are always aware at the function level you are dealing with it.
A quick 'grep global *.php' will show you who is fiddling with it.
> For example, a coworker of mine has a stylistic thing where he loathes
> testing complicated conditions. So, before anything that's really
> complicated he'll start setting flag variables and things far up in the
> code before the condition test, sometimes multiple times changing the
> value, or assigning more than one flag at a check, which means every
> damn time I want to follow the value of a variable, I end up having to
> follow five or six instead, just to see the consequences.
>
Kick him in the balls.
If I do a line of complicated conditionals, there is usually three to 5
lines of comment above it. Heck even though I doubt anyone else will
ever fix bugs in it, it helps ME 6 months down the line when I have to
fix some obscure condition, to see what it was SUPPOSED to do. Even if
the code fails to achieve its aims..;-)
I learnt that coding assembler..mostly assembler bears no lexical
correlation to the functionality of the code. It NEEDS comments, lots of
em. Not one per line as the 'rules' said, but certainly a big one per
logical block.
Anyway global variables are dead useful in e.g. state machines, and in
error handling. There is a tendency to obscure them in OOP buy binding
them a static data inside 0bjects and using methods to get at them, but
the result is really the same. Its just cleaner and less overhead to use
a global..
I think your meaning went completely over TNP's head.
Of course, that's not surprising. But hopefully others understand.
I once knew a FORTRAN! :>} programmer (some 40 years ago!) who was so
proud that all his labels were BINARY (010001, 010010. etc.),and all of
his fixed point variables started with "I" and floating variables with
"O", and the rest of each variable name was a mix of 0, 1, O, and I!
Impossible to read his code!!!!
John Kopf
> What I need is a (hopefully, pdf) manual or specification for PHP that I
> can download and refer to off-line, and which is complete enough to
> actually mention things like "global"...Most just give lists of the
> common string functions, with (VERY) simple examples.
>
You can download docs here: http://www.php.net/download-docs.php
But better to look online because you can find very usefull comments
on site.
To find page about something just add this to PHP site name. For
example http://www.php.net/global to see variable score page with
description about 'global' keyword.