.. _classes-cantinstantiateclass: .. _can't-instantiate-class: Can't Instantiate Class +++++++++++++++++++++++ When constructor is not public, it is not possible to instantiate such a class. Either this is a conception choice, or there are factories to handle that. Either way, it is not possible to call new on such class. .. code-block:: php See also `In a PHP5 class, when does a private constructor get called? `_, `Named Constructors in PHP `_ and `PHP Constructor Best Practices And The Prototype Pattern `_. Related PHP errors ------------------- + `0 `_ Connex PHP features ------------------- + `constructor `_ + `visibility `_ Suggestions ___________ * Make the constructor public * Create a factory, as a static method, in that class, to create objects * Remove the new call Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Classes/CantInstantiateClass | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`Changed Behavior ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 1.2.8 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Critical | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-wordpress-classes-cantinstantiateclass` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+