Re: Functions

From: Date: Wed, 17 Jan 2001 16:20:56 +0000
Subject: Re: Functions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35064@lists.php.net to get a copy of this message
> echo foo(dog); // outputs "This is a dog" This is an example of using a "bareword" - PHP doesn't recognize _dog_ as any sort of reserved word or constant, so it sends it like a quoted string. I don't recommend using this because it's ambiguous whether you mean "dog" or if _dog_ is a constant or whatever else is possible. > echo foo('dog'); // outputs "This is a dog" Single-quoted string: this is good for strings that don't need to be "interpretted" by the parser; it's the ideal way to pass the string 'dog' to foo() in this case. > echo foo("dog"); // outputs "This is a dog" Double-quoted string: this WILL be interpretted by the parser; for example, if you had to pass the whole string "This is a dog" to the function, but "dog" could actually be any word contained in $thing, then you'd do something like this: echo foo("This is a $thing"); Et cetera... > > Does it matter which way I pass my arguments to foo? All arguments were > passed as a string variable. There are some very slight performance changes between these, but mostly it's a matter of style. --Toby

« previous php.general (#35064) next »