Take this CakePHP source file for example: cake/libs/model/model.php. In
there you'll see:

if (phpversion() < 5) {
         require(LIBS . 'model' . DS . 'model_php4.php');

         if (function_exists("overload")) {
                  overload("Model");
         }
} else {
         require(LIBS . 'model' . DS . 'model_php5.php');
}

You can see there that CakePHP loads different files depending whether you
are using PHP4 or PHP5 (on some cases, such as model. AFAIK there's no other
example of this kind of behavior.

Now, if you are using PHP4 __construct() is not called automatically when
instantiating a class, but CakePHP brings the PHP5 world into PHP4 by using
the class Object as ancestor of all its classes. Take a look at the file
cake/libs/object.php and you'll now see:

        function Object() {
                $args = func_get_args();
                if (method_exists($this, '__destruct')) {
                        register_shutdown_function (array(&$this,
'__destruct'));
                }
                call_user_func_array(array(&$this, '__construct'), $args);
        }

You can see then how CakePHP tricks it on PHP4, by registering the
destructor of an object as a shutdown function, and by automatically calling
__construct() on instantiation.

Therefore, you should not declare your constructor as public but rather the
PHP4 way. Well, that is, if you want to keep PHP4/PHP5 compatibility. If you
are running on PHP5 your constructor will be called as expected, and if you
are running on PHP4 CakePHP will take care of the call for you.

-MI

---------------------------------------------------------------------------

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!


-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de ivan
Enviado el: Martes, 12 de Diciembre de 2006 08:06 p.m.
Para: Cake PHP
Asunto: Re: choosing php4 or php5

what i don't get it yet is, let's say i'm working over php5 so i use my
constructors like this

public function __construct(){}

the cake core must have its constructors, doesn`t it? so which
constructors way is using? if it is using php4 way, does it means there
is any advantage that is not used to 100% or it just doesn't matter at
all?


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to