Yes. PHP will simply create any member variables that are referenced but have not been declared. I just tested it with the following code:
<?php
class Test {
public function __construct() {
}
public function setMembers() {
$this->foo = "fooValue";
$this->bar = "barValue";
}
public function echoMembers() {
echo $this->foo . "\n";
echo $this->bar . "\n";
}
}
$test = new Test();
$test->setMembers();
$test->echoMembers();
?>
When executed, this outputs:
fooValue
barValue
Which proves that this works. I still recommend declaring all class member variables at the top of the class. It's what the OO programmers maintaining your code will expect to see.
FYI: I ran my test with the following version of PHP:
$ php -version
PHP 5.2.8 (cli) (built: Feb 5 2009 21:21:13)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies