Solved

the (), $poppy = new poodle; and $bill = new person();

Posted on 2008-06-24
2
205 Views
Last Modified: 2008-06-24
When should an object be created with ()?
When should an object be created without ()?
0
Comment
Question by:locke2005
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 21859348
the () are optional, unless you want to call a construtor with arguments...
0
 
LVL 1

Assisted Solution

by:morristhebear
morristhebear earned 125 total points
ID: 21859372
I tend to only use parenthesis when I've overwritten the constructor to allow parameters to be passed into the instantiantion request.

See example classes below.  Maybe this is just me, if you haven't written a __construct method it shouldn't matter which you use.  I'm sure there's no overhead using parenthesis when you haven't overwritten the __construct.
<?php
 
	class Dog {
		
		public function __construct ($dog_color) {
			//	Whatever else here.
		}
		
	}
	
	class Cat {
		
	}
	
	$dog = new Dog ('brown');
	$cat = new Cat;
	
?>

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question