0

Not really sure how to search this, but is there really a difference between these two?

$t = new Test();
// vs...
$t = new Test;
j08691
  • 204,283
  • 31
  • 260
  • 272
Ascherer
  • 8,223
  • 3
  • 42
  • 60

4 Answers4

1

There are generally accepted rules and they must adhere to.

$t = new Test();

True choise

Norbrecht
  • 71
  • 3
  • 11
  • This convention is most likely inherited from Java, which PHP attempts to emulate in some ways, however "true choise" does not make much sense. Could you please clarify ? – SirDarius Sep 05 '13 at 17:15
1

There is no difference. The __construct() method is executed with both.

Martin Lantzsch
  • 1,851
  • 15
  • 19
1

There is no differance

Look here:

<?php

class Test {
    function printTest() {
        echo "Test";    
    }
}

$t = new Test();
echo $t->printTest();
// vs...

$t = new Test;
echo $t->printTest();

?>

Output:

Test //from Test()
Test //from Test
MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89
1

If the __construct method needs to take in some parameters then you should use

$t = new Class('Param1','Param2'); 

If it doesn't need to take any parameters then there is no difference between using

$t = new Class;

OR

$t = new Class();
Ali
  • 3,479
  • 4
  • 16
  • 31