I want to pass the value of a variable I defined in a class to its method. I know I can set a default value using the =
notation within the parentheses of the method, but this seems redundant since I already have the variable defined. Is this possible?
class Car { var $num_wheels = 4; var $model = "BMW"; function MoveWheels($num_wheels, $model) { echo "The $num_wheels wheels on the $model are spinning."; } } $bmw = new Car(); $bmw -> MoveWheels();
I found the answer to my question! You can pass class-defined variables to a method using
$this->
. Doing so completely eliminates the need to put variables within parentheses of the method.