Solved

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

Posted on 2008-06-24
2
203 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
Comment Utility
the () are optional, unless you want to call a construtor with arguments...
0
 
LVL 1

Assisted Solution

by:morristhebear
morristhebear earned 125 total points
Comment Utility
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Adding Extra Information box 4 23
Jquery Autocomplete PHP script 3 20
php image upload 3 23
wordpress issue 2 14
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now