Solved

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

Posted on 2008-06-24
2
208 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

738 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