note 129539 added to function.define
| From: | theking2(at)King.na | Date: | Wed, 05 Jun 2024 20:39:51 +0000 |
| Subject: | note 129539 added to function.define | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221344@lists.php.net to get a copy of this message | ||
As PHP objects are technical arrays it is possible to assign objects to constants with the advantage
that these are available everywhere.
This for instance can be used for a logger object based on monolog
<?php
$log = new Monolog\Logger( 'test' );
define( 'LOG', $log );
unset($log);
?>
Even after unsetting the constant LOG can be used like LOG->denug("test").
Tested in php 8.0
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 89.39.107.202)
----
Manual Page -- https://php.net/manual/en/function.define.php
Edit -- https://main.php.net/note/edit/129539
Del: integrated -- https://main.php.net/note/delete/129539/integrated
Del: useless -- https://main.php.net/note/delete/129539/useless
Del: bad code -- https://main.php.net/note/delete/129539/bad+code
Del: spam -- https://main.php.net/note/delete/129539/spam
Del: non-english -- https://main.php.net/note/delete/129539/non-english
Del: in docs -- https://main.php.net/note/delete/129539/in+docs
Del: other reasons-- https://main.php.net/note/delete/129539
Reject -- https://main.php.net/note/reject/129539
Search -- https://main.php.net/manage/user-notes.php