oop - Constructor Overloading in PHP -
problem approch
i have class overloaded constructors
code
<?php /* users abstract class */ abstract class user { protected $user_email; protected $user_username; protected $user_password; protected $registred_date; //default constructor function user() { } //overloded constructor function user($input_username,$input_email,$input_password) { __set($this->user_username,$input_username); __set($this->user_email,$user_password); __set($this->user_password,$input_password); } } ?>
problem details
above code provides error : error:fatal error: cannot redeclare user::user()
as other languages such c++ , java uses above approach overload constructors how in php oop ?
additional information
im using *php 5.3.2 in lamp * oop concepts should supported in version
php doesn't have overloading. has series of magic methods described overloading in manual (see: http://php.net/manual/en/language.oop5.overloading.php), it's not you're thinking of.
also, aside, correct way write constructor in php 5+ use __construct method:
public function __construct(/* args */) { // constructor code }
Comments
Post a Comment