oop - PHP 5.3 constructor method -


i java/c# programmer trying learn/finish project in php. can explain me why "composition" doesn't work in php 5.3 1 expect object oriented language?

i have tried research issue, due term-confusion (making google useless...) , bad documentation, haven't been able find useful yet.

<?php /*php version 5.3.3*/  class myclassone {     public function myfunctionone()     {         echo "<p> function 1 </p>";     } }  class myclasstwo {     private $myclassone;      function __constructor() // wrong wrong wrong - __construct() - , works.     {         $this->myclassone = new myclassone();     }      public function myfunctiontwo()     {         echo "<p> function 2 </p>";         $this->myclassone->myfunctionone(); // crashes "application"     }  }   $myclassone = new myclassone(); $myclassone->myfunctionone(); $myclasstwo = new myclasstwo(); $myclasstwo->myfunctiontwo();   /* expectet result: function 1 function 2 function 1  real result: function 1 function 2 (application/runtime crash) */  ?> 

it highly appreciated if can provide explanation or show me relevant documentation behavior.

you have typo. change __constructor __construct , work correctly.

php constructors should named __construct() per the documentation.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -