Note that there are some explanatory texts on larger screens.

plurals
  1. POLate static binding
    primarykey
    data
    text
    <p>I've got a little problem. Here it is:</p> <ol> <li><p>This is my singleton abstract class:</p> <pre><code>abstract class Singleton { protected static $_instance = NULL; /** * Prevent direct object creation */ final private function __construct() { $this-&gt;actionBeforeInstantiate(); } /** * Prevent object cloning */ final private function __clone() { } /** * Returns new or existing Singleton instance * @return Singleton */ final public static function getInstance(){ if(null !== static::$_instance){ return static::$_instance; } static::$_instance = new static(); return static::$_instance; } abstract protected function actionBeforeInstantiate(); } </code></pre></li> <li><p>After that I create an abstract registry class:</p> <pre><code>abstract class BaseRegistry extends Singleton { //... } </code></pre></li> <li><p>Now it's time for session registry.</p> <pre><code>class BaseSessionRegistry extends BaseRegistry { //... protected function actionBeforeInstantiate() { session_start(); } } </code></pre></li> <li><p>The final step:</p> <pre><code>class AppBaseSessionRegistryTwo extends BaseSessionRegistry { //... } class AppBaseSessionRegistry extends BaseSessionRegistry { //... } </code></pre></li> <li><p>Testing</p> <pre><code>$registry = AppBaseSessionRegistry::getInstance(); $registry2 =AppBaseSessionRegistryTwo::getInstance(); echo get_class($registry) . '|' . get_class($registry2) . '&lt;br&gt;'; </code></pre></li> </ol> <p>Output:</p> <pre><code>AppBaseSessionRegistry|AppBaseSessionRegistry </code></pre> <p>My expectations were:</p> <pre><code>AppBaseSessionRegistry|AppBaseSessionRegistryTwo </code></pre> <p>Why did I get such result? And how can I remake my code to obtain result that I expected?</p> <p><strong>UPDATE:</strong> i use this in my framework. And users will extend my <code>BaseSessionRegistry</code> class and will add their stuff. I want to solve this inside my framework classes</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload