Solved

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

Posted on 2008-06-24
2
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 …

632 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