?
Solved

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

Posted on 2008-06-24
2
Medium Priority
?
210 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 500 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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …
Suggested Courses

718 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