Assuming (for some reason and design), in the method, in the case of the default parameter, we just want to use the attribute instead, than I would also do it like Alex:
public function methodABC($param = NULL) {
if ( $param === NULL ) {
$param = $this->attributeUVW;
}
...$param...
}
... and here is the full code for the game (my 2 cents):
<?php
class MyClass
{
public $attributeUVW;
function __construct() {
$this->attributeUVW = 1234;
}
public function methodABC($param = NULL) {
if ( $param === NULL ) {
$param = $this->attributeUVW;
}
echo '<p>"'.$param.'"</p>'."\n";
}
}
echo '<html>'."\n";
echo '<body>'."\n";
echo '<h1>class X</h1>'."\n";
$x = new MyClass;
$x->methodABC();
$x->methodABC(5678);
echo '</body>'."\n";
echo '</html>'."\n";
?>
... prints:
source
share