CodeIgniter'daki yapıcı olarak Sınıfadı () veya __ construct () kullanın?

2 Cevap php

i CodeIgniter'daki yapıcı olarak Sınıfadı () veya __ construct () kullanmalıyım?

hem iş, ben hangi kullanmalıyım?

2 Cevap

Classname() eski yoludur (i.e. PHP 4 way).

__construct(), yeni (i.e. PHP 5) yoludur.

Eğer uygulama PHP 5 ile yazılmış ise, ikinci birini kullanın -- and you should write your applications with PHP 5 in mind ! olmalıdır


See the Constructors and Destructors section in the manual, which states (quoting) :

For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class.

ClassName() ve __construct() yapıcısı olarak bilinen bu aynıdır.

Eğer değiştirmek için ClassName() Eğer yapıcı ismini fakat {değiştirmek gerek değiştirmek zorunda çünkü __construct() function className() en yararlı karşılaştırma [(0)] } ve aynı zamanda çocuk sınıfta kullanın.