Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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

When should an object be created with ()?
When should an object be created without ()?
0
locke2005
Asked:
locke2005
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the () are optional, unless you want to call a construtor with arguments...
0
 
morristhebearCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now