Re: [PHP] Strange problem in class creation

This is a discussion on Re: [PHP] Strange problem in class creation within the PHP General forums, part of the PHP Programming Forums category; > > > And the error is strange because you're doing > > something strange! > > I don'...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-12-2003
Mukul Sabharwal
 
Posts: n/a
Default Re: [PHP] Strange problem in class creation

>
> > And the error is strange because you're doing
> > something strange!

>
> I don't think I'm doing anything strange. What I
> have exposed here is a simplification of my own
> class loader. I have the main class that must
> load (include and then instance) other PHP classes.
> The problem is that if I do instance other classes
> in the loader > constructor they get a "copy" of the
> loader instance and not the real
> instance reference.


That code (looked closely) confirms you're doing
something strange :)

A constructor cannot call (or rather should not call)
"itself" while being constructed. It leads to
"unexpected" results.

So technically in some cases you might be able to get
it, but on most occassions you won't, it depends on
how your class is made. And yours recurses, I'm
presuming you wanted that for some reason (??)

On almost all times your data will be still pointing
to your base class (second_class).

So i'm afraid your method is not reliable, dangerous
none the less.

The reliable and correct way of doing it is after your
constructor has finished your class and made it ready
(guaranteed), then you can do what you want to.

=====
Mukul Sabharwal (mjsabby@yahoo.com)

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:59 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0