Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> funkcja include i require
RedDoom
post 12.06.2010, 12:44:31
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 12.06.2010

Ostrzeżenie: (0%)
-----


Mam problem z tymi funkcjami.

Mam plik 'Draw.inc'
  1. <?php
  2. class Location {
  3. public $Left;
  4. public $Top;
  5. public function __construct() {
  6. $this->Top=0;
  7. $this->Left=0;
  8. }
  9. ?>


Nastepny plik 'control.inc'
  1. <?php
  2. include ('Draw.inc')
  3. class Draw {
  4. public $Location;
  5. public function __construct() {
  6. $this->Location=new Location;
  7. }
  8. ?>


i plik ktory uruchamiam 'test.php'
  1. <?PHP
  2. include('control.inc')
  3. $D=new Draw;
  4. $D->Location->Top=5;
  5. ?>

i otrzymuje taki komunikat
Fatal error: Class 'Location' not found in control.inc on line ...
czy ktos mi moze wytlumaczyc co robie zle
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
bastard13
post 12.06.2010, 13:49:55
Post #2





Grupa: Zarejestrowani
Postów: 664
Pomógł: 169
Dołączył: 8.01.2010
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Masz racjęsmile.gif powinno być:
  1. define(SCIEZKA,'sciezka_z_plikami_klas');
  2. function __autoload($class_name)
  3. { if(file_exists(SCIEZKA.$class_name.'.php'))
  4. require(SCIEZKA.$class_name.'.php');
  5. }


--------------------
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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 14:08