|
Posted by Niels Ganser on 10/18/12 11:28
Thanks for your reply, Jasper.
auto_append_file has been my first "alternative" approach too and so far
it seems to be the best option available. But the show-stopper to me is
that if you exit() out of your script, the file won't be appended.
I did write some sort of wrapper function to first append the file and
then do an exit(), however an error (obviously no notices or warnings)
will still prevent the file from being loaded.
You may argue that e.g. an E_ERROR will stop exection of the script
anyway and no shutdown handler will be called whatsoever but this is
only partially right as an error in an included file won't stop the
shutdown handler (registered in the including file) from being called.
So if i depend on objects (which have been initialized during script
runtime) even after an error occured, apparently there still is no way
to do it.
You may wonder what all the fuss is about, thinking that this is only a
theoretical problem. I'm collecting debugging information during script
runtime and store them in an object's properties. At the very end of my
script I want those information to either be displayed or logged. As you
can imagine, those information are a lot more valuable in an error
context.
I _could_ save them in a global variable which I could access without any
problem in my shutdown function, however I'm quite happy with the
flexibility of my object oriented approach and rather wouldn't like to
change it.
Anymory ideas?
Regards,
Niels
Jasper Bryant-Greene:
> Niels Ganser wrote:
> > I use a Debugger-Class to collect debugging information (now that was
a
> > hard guess, wasn't it..) during script runtime. In order to collect
> > everything there is to collect, I instantiate a debugger object right
at
> > the start of my scripts and unload this object at the very end of my
> > shutdown function.
> >
> > Unfortunately as of PHP 5.0.5 objects get unloaded before the
shutdown
> > function is even called and as Jani Taskinen pointed out [1] this
> > behaviour is very much intended and won't get changed (whatever the
> > reason for this decision might be..) with all related bugs marked
Bogus
> > [2] or a documentation issue [3].
> >
> > I have to admit that it wouldn't be much of a deal to store the
debugging
> > information outside the object but I like the approach I took and
fear
> > that I might run into other problems with objects getting destroyed
> > before others which depend on the previous ones, so my question is
> > (tadaa): Is there a way to sort of "customize" the order in which
> > objects are unloaded during the shutdown procedure? I have to stress
> > that defining the classes and/or instantiate the objects in a
specific
> > order is _not_ an option.
> >
> > [1] http://marc.theaimsgroup.com/?l=php-dev&m=112556389406774
> > [2] http://bugs.php.net/bug.php?id=34377
> > [3] http://bugs.php.net/bug.php?id=33772
>
> This is a really nasty bug, which has been preventing me from upgrading
> to PHP 5.0.5. Unfortunately it doesn't look like it will be fixed any
> time soon. The most descriptive bug report is [3], bug ID 33772, above.
>
> The only workaround I've come up with (although pretty ugly) is to use
> an auto_append_file [1] that executes the necessary destructors in the
> order you want them. This file will be executed before PHP starts
> destroying objects.
>
> HTH
>
> [1] http://php.net/ini.core#ini.auto-append-file
[Back to original message]
|