Senior & Expert PHP Developers Discussion Forum by Nyros Technologies

HIRE PHP Expert Developers Programmers Coders From India
PHP .Net Ruby on Rails Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

construtor in PHP with OOPS

 
Post new topic   Reply to topic    Senior & Expert PHP Developers Discussion Forum by Nyros Technologies Index -> MySQL connect
View previous topic :: View next topic  
Author Message
ravishankar



Joined: 05 Feb 2010
Posts: 4

PostPosted: Tue Feb 09, 2010 3:17 pm    Post subject: construtor in PHP with OOPS Reply with quote

Hi All,

I am a beginner to OOPS in PHP.Can you explain Construtor concept in oops with Examples.

Thanks in Advance

Ravi
Back to top
View user's profile Send private message
Thirupathi



Joined: 01 Dec 2009
Posts: 116

PostPosted: Wed Feb 10, 2010 3:32 am    Post subject: Constructors in php Reply with quote

Hi Ravisankar,
Constructor:
--------------
Constructor is special function in a class that is automatically called when you create new instance of class with new key word.If class has no constructor then the constructor of base class is being called.
Constructor can take arguments,these arguments can be optional which makes them much more useful.

<?php
class Test{

function Test($name = "Defalult Employee Name",$no = "Default Employee No"){
$this->empName = $name;
$this->empNo = $no;
}
function disply(){
echo $this->empName ."<br />";
echo $this->empNo ."<br />";
}
}
$obj1 = new Test(); //here we are calling default constructor.
$obj1->disply();

$obj2 = new Test("Employee1",101); //here we are calling argumented constructor with two values.
$obj2->disply();

$obj3 = new Test("Employee2"); //here we are calling argumented constructor with one value.
$obj3->disply();

?>

constructor function name must be as class name but in php5 unified constructor is available.so that we can use __construct() instead of using the class name.

You can go through that example i think you may get clarity about your dobht.

Thanks & Regards,
Thirupathi.J
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert PHP Developers Discussion Forum by Nyros Technologies Index -> MySQL connect
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts About foxycart
0 venkatadapa 5 Fri Jul 30, 2010 10:02 am
venkatadapa View latest post
No new posts How to change the mysql storage engine from MyISAM to innodb
1 aababu 10 Fri Jul 30, 2010 9:57 am
venkatadapa View latest post
No new posts How can we increase the execution time of a php script?
0 samir 6 Fri Jul 30, 2010 4:15 am
samir View latest post
No new posts Get no of days between two dates & current dates using M
0 samir 4 Fri Jul 30, 2010 4:09 am
samir View latest post
No new posts What are the different types of errors in php
0 samir 6 Fri Jul 30, 2010 4:00 am
samir View latest post
No new posts How to remove a value in an array using javascript
0 samir 10 Thu Jul 29, 2010 7:27 am
samir View latest post
No new posts Agile methodology plays vital role in software development
0 venkatadapa 7 Thu Jul 29, 2010 7:20 am
venkatadapa View latest post
No new posts How to get complete information about $_SERVER variable
0 Sanjana 15 Wed Jul 28, 2010 6:58 am
Sanjana View latest post
No new posts DNL Reader for php website
0 Mike 22 Mon Jul 26, 2010 12:33 pm
Mike View latest post
No new posts Use mysql_real_escape_string() function to avoid mysql injec
0 venkatadapa 26 Mon Jul 26, 2010 11:05 am
venkatadapa View latest post





Hire an expert PHP developer / coder / programmer or development team from India now!!

Other Forums : Ruby on Rails   ::   .Net   |   Free unlimited HTML CSS Joomla Wordpress Drupal templates download

Nyros Technologies   |   Developers Blog   |   Kakinada City Portal   |   About PHP Experts   |   More