Reply to Re: constructor overloading in php

Your name:

Reply:


Posted by Rik on 10/17/16 11:49

emrahayanoglu@gmail.com wrote:
> i tried like other languages. This is an example.
> PHP5
>
> class emr
> {
> function __construct($username)
> {
> }
> function __construct($username, $password)
> {
> }
> function __construct($username, $password, $name)
> {
> }
> }

If that's what you wnat, why not declare some defaults for the variables:
function __construct($username, $password=false, $name=false)
{
if($name!==false)//execute some code
if($password!==false)//domething else
}
Etc.
Which makes you able to:
$a = new emr('username');

And all arguments left out will result in their default values.

Else, it's up to the earlier mentioned func_get_args();

Grtz,
--
Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация