You are here: Re: classes: strange behavior « PHP Programming Language « IT news, forums, messages
Re: classes: strange behavior

Posted by Jerry Stuckle on 05/06/06 21:30

Paul Czubilinski wrote:
> Hello,
>
> I have a problem with code like this (PHP 5.1.4):
>
> fila A.php:
> =======
>
> include(B.php);
> class document extends obj {
> .........
> }
>
> file B.php:
> =======
>
> $GLOBALS['x']->new we();
>
> function __autoload($class_name) {
> ...here is the code to load classes...
> }
>
> file C.php
> =======
>
> class we extends obj {
>
> private $document;
>
> function __construct() {
> $this->document = new document();
> }
>
> }
>
>
> The problem is that after loading A.php into browser, PHP cannot find
> document class which is defined in the A.php file! The problem is even
> more strange - if document class doesnt extends obj class than
> everything is ok.
>
> (The problem exact is that __autoload special function is called when
> in file C.php constructor of class we try to make the document object
> (all other classes like obj has been already loaded).
>
> Do you have any idea what is wrong with that?
>
> Paul
>

Paul,

I'm not exactly sure of what your problem is here. But I think you may be
misunderstanding how PHP works.

First of all A.php is not "loaded into the browser". The browser may load the
page - but this means the PHP is executed on the server and its output
(generally html or xml) is sent to the browser.

Once it completes execution, all the PHP stuff is discarded (other than data
saved in $_SESSION). The next page loaded will start fresh.

So in order for C.php to know anything about document, C.php must include A.php.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация