473,372 Members | 924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 32185

em***********@gmail.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($username)
{
}
function __construct($username, $password)
{
}
function __construct($username, $password, $name)
{
}
}
Then i have that error:Fatal error: Cannot redeclare emr::__construct()

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

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


See my reply in alt.comp.lang.php; in short: Overloading like in Java is not
supported in PHP.
JW
Jun 4 '06 #4
Rik
em***********@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
Jun 5 '06 #5

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

Similar topics

2
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...
26
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
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...
8
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
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...
14
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
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...
7
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
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...
12
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? ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.