Bu işe yaramazsa:
test.php:
include_once('test-include.php');
$main = new mainClass();
//======================================================================
class mainClass {
function __construct() {
$test2 = new Test2();
echo $test2->var;
}
}
//======================================================================
class Test2 extends Test1 { // test2
var $var = 'b';
}
test-include.php:
// this does get printed out, so I know the include statement is working
echo 'DEBUG: this is the test-include.php file<br>';
//======================================================================
class Test1 { // test1
var $var = 'a';
}
Bu aşağıdaki hatayı veriyor
PHP Fatal error: Class 'Test2' not found in /path/to/test.php on line 8
Bu işi yapmaz
test2.php:
// this is in the same position as the include statement in test.php
//======================================================================
class Test1 { // test1
var $var = 'a';
}
$main = new mainClass();
//======================================================================
class mainClass {
function __construct() {
$test2 = new Test2();
echo $test2->var;
}
}
//======================================================================
class Test2 extends Test1 { // test2
var $var = 'b';
}
Neden bulunamıyor bunu uzanan çocuğun sınıfını neden bir içerme dosyası Taban sınıf (Test1) koyarak mı? Biz bunu oluşturmaya çalıştığınızda bu Test2 bulamıyorum çünkü başka deyişle, ilk örnek başarısız oluyor. Henüz kod yürütme akışındaki Test2 için kazanılmış değil gibi bu tür mantıklı. Ancak, ikinci örnekte (deyim dahil olmadan) hiçbir hata (henüz kod yürütülmesine Test2 sınıfını ulaşmış değil) benzer bir durum olsa bile, orada
Oh, ve bu sürüm 5.1.6 altında.
UPDATE:
Tamam, Daff doğru - Ben taşırsanız
$main = new mainClass();
dnm.php örnekte sonuna kadar çalışır. Ben yine yukarıdaki satır sonunda değil eğer işe yaramazsa neden bilmek istiyorum - bu sonunda $ ana = new MainClass () hattı yok test2.php örnekte sadece çalışıyor .
UPDATE 2:
Bu işin hiçbiri - Tamam, ben include_once
yerine require, require_once
ve include
kullanarak denedim. Ve ben de test include.php dosya için bir test echo deyimi eklenmiş ve dışarı basılmış olur (artı bir varolmayan dosya dahil ilgili bir hata alamadım) bu yüzden deyimi çalışıyor içerir biliyorum.