Linked by John Collins on Wed 21st Apr 2004 06:42 UTC
The purpose of this article is to give a novice programmer the basic idea of what OOP is, as implemented using PHP. Readers should have a basic knowledge of programming ie what variables are, variable types, basic methods of writing comments, and how to enter code into a text editor.
Permalink for comment
To read all comments associated with this story, please click here.
When using variable interpolation in PHP (which occurs automatically with double quoted strings but not with single), the braces act to disambiguate variables from the surrounding text.
Example:
$foo = 'spam'
$bar = '$foo to you'
$wrongbaz = "$foos to you"
$baz = "{$foo}s to you"
echo $foo, $bar, $wrongbaz, $baz
Should print:
spam
$foo to you
$foos to you
spams to you
Notice that it's impossible to tell whether you mean to look up the variable $foos or whether you're trying to add an 's' onto variable $foo, hence the need for braces.
When using variable interpolation in PHP (which occurs automatically with double quoted strings but not with single), the braces act to disambiguate variables from the surrounding text.
Example:
$foo = 'spam'
$bar = '$foo to you'
$wrongbaz = "$foos to you"
$baz = "{$foo}s to you"
echo $foo, $bar, $wrongbaz, $baz
Should print:
spam
$foo to you
$foos to you
spams to you
Notice that it's impossible to tell whether you mean to look up the variable $foos or whether you're trying to add an 's' onto variable $foo, hence the need for braces.