php class basic question

Posted by Ross on Stack Overflow See other posts from Stack Overflow or by Ross
Published on 2010-03-19T13:31:10Z Indexed on 2010/03/19 13:41 UTC
Read the original article Hit count: 184

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about class