Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]instancja klasy w klasie
-Gość-
post
Post #1





Goście







Dlaczego konstrukcja taka:

Kod
<?php

include "klasa_a.php";

$a= new A();

$a= new A();

?>


klasa_a.php

Kod
<?php
class A
{
    function __construct()
    {
        include "klasa_b.php";
        $b= new b();

    }
    
}


?>


wywala błąd PHP Fatal error: Cannot redeclare class b

a konstrukcje

Kod
<?php

include "klasa_a.php";

$a= new A();

$a= new A();

?>


klasa_a.php

Kod
<?php
class A
{
    function __construct()
    {
        
    }
    
}


?>


i

Kod
<?php

include "klasa_a.php";

$a= new A();

?>


klasa_a.php

Kod
<?php
class A
{
    function __construct()
    {
        include "klasa_b.php";
        $b= new b();

    }
    
}


?>


działa poprawnie ?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 07:34