> Apparently it does not like the function name to be the same as the class 
> name. So change one of them.

No, what's happening is that when you instantiate an class, it runs
(as a constructor) the function whose name is the same as the class.

So when you do this:

$first = new first;

it's automatically running the class' "first()" method.  Now, because that method 
is defined as requiring parameters, you need to do this:

$first = new first( 35, "Chris" );

Alternately, you can define your function/method thusly:

first($age = 0, $name = '');

but that isn't going to accomplish anything other than getting rid of the errors.
You either want to create a constructor that initializes all the member variables
or not create a constructor at all.
This would be a better way of writing your class:

class first
{
        var $age;
        var $name;

        function first()
        {
          $age = 0;
          $name = '';
        }

        function setData( $age, $name )
        {
          $age = $age;
          $name = $name;
        }

        function returnData()
        {
          $retval = '';

          $retval  = $this->age;
          $retval .= $this->name;

          return $retval;

        }
}

Chris
(also)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to