473,883 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

constructor overloading in php

Hello Everyone,

I looked everywhere for that problem. Does anyone know that how can i
overload constructor function in php 5?

Best Regards,

Emrah Ayanoglu

Jun 4 '06 #1
4 32221

em***********@g mail.com wrote:
Does anyone know that how can i
overload constructor function in php 5?


Yes. PHP4 or PHP5? What have you tried already?

Jun 4 '06 #2
i tried like other languages. This is an example.
PHP5

class emr
{
function __construct($us ername)
{
}
function __construct($us ername, $password)
{
}
function __construct($us ername, $password, $name)
{
}
}
Then i have that error:Fatal error: Cannot redeclare emr::__construc t()

Jun 4 '06 #3
em***********@g mail.com wrote:

Don't multipost
i tried like other languages. This is an example.
PHP5


See my reply in alt.comp.lang.p hp; in short: Overloading like in Java is not
supported in PHP.
JW
Jun 4 '06 #4
Rik
em***********@g mail.com wrote:
i tried like other languages. This is an example.
PHP5

class emr
{
function __construct($us ername)
{
}
function __construct($us ername, $password)
{
}
function __construct($us ername, $password, $name)
{
}
}


If that's what you wnat, why not declare some defaults for the variables:
function __construct($us ername, $password=false , $name=false)
{
if($name!==fals e)//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
Jun 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5266
by: Sergey Krushinsky | last post by:
Hello all, Is there a common way to emulate constructor overloading in Python class? For instanse, I have 3 classes: 1/ Polar - to hold polar coordinates; 2/ Cartesian - to hold cartesian coordinates; 3/ Coordinates3D, which holds synchronized instances of the both in __p__ and __c__ fields respectively.
26
21354
by: Paul | last post by:
public class A { public A () { // here I would like to call the second version of _ctor, how to accomplish this ? } public A (int a, int b, int c) {
19
3591
by: Martin Oddman | last post by:
Hi, I have a compiling problem. Please take a look at the code below. I have an application that is built upon three tiers: one data tier (Foo.DataManager), one business tier (Foo.Kernel) and one web presentation tier (Foo.WebFiles). The data tier shall only be accessible thru the business tier so I do NOT want a reference to the data tier in the presentation tier. In the business tier I have a class with the name CategoryItem that...
8
2258
by: Sam Sungshik Kong | last post by:
Hello! I am wondering what's the best practice about setting object data using constructor parameters. Let's say that I am creating a Person class. class Person { private string name;
31
5207
by: Peter E. Granger | last post by:
I'm fairly new to C++ and VC++, but for the most part it seems to do most of the same things that can be done in Java, with just some syntactic and structural adjustments. However, one thing I haven't been able to figure out is how to call one constructor from another within a class. It's easy enough to call the base class's constructor from the derived class, but that's not what I'm trying to do. For example, in Java (or J#) it's easy...
14
1746
by: Klaus Löffelmann | last post by:
Hi, does anybody know, why the second contructor isn't called in this example? Are you able to reproduce this bug? Thanks Klaus Public Class Something
7
2377
by: Doug | last post by:
Hi I am working through a learning module privately where there is discussion about overloading the constructor. Could someone please let me know the benefit or purpose of doing this in a class? Thanks
7
4163
by: coinjo | last post by:
i have to overload a constructor that takes a constant static public data member of a class... Can anybody tell me its syntax of prototype and implementation?
22
3637
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float v);
12
7234
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? class Trial { public: Trial() {
0
9944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9796
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10860
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9583
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7975
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7134
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5804
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3239
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.