# [PATCH] unregister_shutdown_function()

- Thread: https://externals.io/message/53373
- Original archive: https://news-web.php.net/php.internals/53373
- Started by Arpad Ray on 2011-06-20T06:36:41+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #53373 — Arpad Ray — 2011-06-20T06:36:41+00:00

URL: https://externals.io/message/53373#53373

Hi,

This patch implements unregister_shutdown_function(), which removes a
function already registered with `register_shutdown_function()`.

It resolves request #53702 (according to google, not sure if it's
still active) and I've thought it a curious absence for a while.

The patch (against trunk) is at:
http://spellign.com/patches/php-trunk-unregister_shutdown_function.patch

N.B. I don't return from the apply func with ZEND_HASH_APPLY_STOP when
it matches because it's also possible to register the same function
twice (maybe a bug?)

Regards,

Arpad

---

## #53386 — johannes@schlueters.de — 2011-06-20T11:37:27+00:00

URL: https://externals.io/message/53373#53386 · In reply to: #53373

> This patch implements unregister_shutdown_function(), which removes a
> function already registered with `register_shutdown_function()`.
> 
> It resolves request #53702 (according to google, not sure if it's
> still active) and I've thought it a curious absence for a while.

Why do you register a shutdown function if you want to remove it again?
Shouldn't you fix the architecture of your code instead of relying on
such functions?

> The patch (against trunk) is at:
> http://spellign.com/patches/php-trunk-unregister_shutdown_function.patch

Does `register_shutdown_function()` work with closures? (Didn't test it)
Then the following should work, too, which isn't the case in your code:

    $a = function() {};
    register_shutdown_function($a);
    unregister_shutdown_function($a);

I also think once that functionality is there the next request will be

    get_registered_shutdown_functions()

or something along the lines.

johannes

---

## #53453 — Arpad Ray — 2011-06-20T21:41:42+00:00

URL: https://externals.io/message/53373#53453

2011/6/20 Johannes Schlüter <johannes@schlueters.de>:
>
> (any reason you sent this privately?)

Nope, must have hit the wrong button ;) back to the list now.

>
> 
> > […]
>
> Then fix the framework or use a better one.

I'm inclined to agree, just providing an implementation. If it's not wanted, ok.

>
> > […]
>
> Good.
>
> > […]
> http://spellign.com/patches/php-trunk-unregister_shutdown_function2.patch
> > […]
>
> Completeness? "Has that stupid shutdown func been registered?"

Fair enough, although I should point out that
unregister_shutdown_function() returns false if the function hadn't
been registered, so if the aim of checking whether it's registered is
to remove it then that's unnecessary.

Regards,

Arpad

---

## #53455 — David Muir — 2011-06-21T00:23:07+00:00

URL: https://externals.io/message/53373#53455 · In reply to: #53453

>
> > […]
> Fair enough, although I should point out that
> unregister_shutdown_function() returns false if the function hadn't
> been registered, so if the aim of checking whether it's registered is
> to remove it then that's unnecessary.
>
> Regards,
>
> Arpad
>

Unless you want to check if a shutdown function has been registered, and
adjust certain behaviour accordingly.
eg, you might want to make sure you exit gracefully prior to doing
something that might trigger a fatal error.

Cheers,
David
