Linked Questions

11 votes
10 answers
9k views

When do/should I use __construct(), __get(), __set(), and __call() in PHP?

A similar question discusses __construct, but I left it in my title for people searching who find this one. Apparently, __get and __set take a parameter that is the variable being gotten or set. ...
Thomas Owens's user avatar
11 votes
5 answers
4k views

__construct() vs method with same name as class

I have recently started php and was wondering the differences between __construct() and having a method with the same name as the class? Is there a reason for using it? All I can work out is it ...
Joe's user avatar
  • 111
6 votes
2 answers
2k views

use Classname() or __construct() as constructor in CodeIgniter?

should i use Classname() or __construct() as constructor in CodeIgniter? both work, which should i use?
never_had_a_name's user avatar
-3 votes
1 answer
3k views

PHP Passing array into class [duplicate]

I'm new ;) I have two file php (and one problem ;) ): index.php: ... $lang = array(); $lang['En'] = 'Enable'; $lang['Dis'] = 'Disable'; ... and the class.print.php ... include_once 'index....
Tony's user avatar
  • 1
1 vote
4 answers
4k views

Assign the value to the Object in php

Actually after fetching the data from the Database, i want to create a new Object and insert this object to the array but when i check the array it shows the NULL value here is my code: <?php $...
Dhruv Tyagi's user avatar
1 vote
2 answers
1k views

Can we declare __constructor and class name constructor in same class?

Can we declare __constructor and class name constructor in same class? If yes, does both get called when object gets created. Also what will be the sequence. If only one will get called then which ...
Rohit Londhe's user avatar
-1 votes
2 answers
411 views

Function definition same name for class in PHP [duplicate]

Why this code print "AA" if I give same name of my class name my function into my class. class A{ public function a() { echo 'A'; } } $a = new A(); $a->a(); // AA Thanks !
Aina's user avatar
  • 28
2 votes
4 answers
109 views

Extending classes in PHP - strange behaviour

First, quote from PHP manual (http://php.net/manual/en/keyword.extends.php): The extended or derived class has all variables and functions of the base class (this is called 'inheritance' despite the ...
confused's user avatar
2 votes
1 answer
57 views

Why is the last method with same name of the namespaced class not considered a constructor in PHP 5.3.3?

The history of PHP says that the older versions of PHP use the class name as a method for a constructor for the same class. The PHP 5.3.3 documentation says that: Methods with the same name as the ...
user avatar
0 votes
1 answer
32 views

Creating objects from classes in PHP results with objects with same data

I have a problem with my classes. I wrote a class item. When I create objects from this class, there is no problem when creating one, but more objects results in initializing all previous objects with ...
Dean's user avatar
  • 16