PHP Classes

Constructor's access scope

Recommend this page to a friend!

      PHP Singleton Trait  >  All threads  >  Constructor's access scope  >  (Un) Subscribe thread alerts  
Subject:Constructor's access scope
Summary:Check constructor's access scope
Messages:2
Author:Alec Joseph Rivera (FOSS Journeyman)
Date:2015-04-14 01:42:24
 

  1. Constructor's access scope   Reply   Report abuse  
Picture of Alec Joseph Rivera (FOSS Journeyman) Alec Joseph Rivera (FOSS Journeyman) - 2015-04-14 01:42:24
I'm thinking there's a way to enforce the constructor's access scope to be private or protected. Statically via abstract declaration or dynamically via checks with reflection.

Do you think the enforcement is advantageous and worth the effort? Should it be done?

Thanks.

  2. Re: Constructor's access scope   Reply   Report abuse  
Picture of Kiril Savchev Kiril Savchev - 2015-04-17 09:21:49 - In reply to message 1 from Alec Joseph Rivera (FOSS Journeyman)
Since now I didn't know that traits can declare class constructors and you are right, it can be enforced to be private or protected, and classes can override it. I didn't think about this at all, thank you very mutch.