php class basic question
- by Ross
hi
<?php
class myClass {
var $input;
var $output;
function myClass($input) {
$output = 'You entered: ' . $input;
return $output;
}
}
$test = new myClass;
echo $test->myClass(123);
?>
this works, but returns this warning:
Warning: Missing argument 1 for myClass::myClass()
I read in to this, and seems that the constructor is expecting a value, so by adding:
function myClass($input='')
the warning is removed, but this seems so unnecessary?
could someone enlighten me as to why it's required to define a value to prevent that warning?
thanks for any pointers