Note that there are some explanatory texts on larger screens.

plurals
  1. POInstantiation in extended classes
    primarykey
    data
    text
    <p>I am working on a custom framework and have a couple of questions about parent class instantiation through child classes.</p> <p>I will paste some code snippets and then get into the questions</p> <pre><code>class CFrameWork { private $applicationName = "Application Name"; function __construct($instance = "development") { echo "Hello, I am the Parent and I have been constructed&lt;BR /&gt;"; } public function startApplication() { $this-&gt;checkMaintenanceMode(); if (!isset($_GET['query'])) { $this-&gt;intialize(); } else { // Call the appropriate controller // Method and function are pulled from the query // Code not displayed // EDITS BELOW if (method_exists($method, $function)) { try { call_user_func(array(new $method, $function), $this); } catch (CFException $exp) { $this-&gt;show404(); exit; } } else { $this-&gt;show404(); exit; } } } } </code></pre> <p>Next we have a controller class</p> <pre><code>class childController extends CFrameWork { function index() { echo "Index Controller"; } function register() { echo "Registration Controller"; } } </code></pre> <p>Now in the index.php, I have</p> <pre><code>$application = new CFrameWork(); $application-&gt;startApplication(); </code></pre> <p>The way this Framework interprets queries: </p> <blockquote> <p>localhost/childController/index - Calls the index() function in class childController localhost/childController/register - Calls the register() function in class childController</p> </blockquote> <p>and so on...</p> <p>So here's my concern. The parent class in this framework in instansiated twice each time a controller method is called. Once by the index.php (where the initial application is created) and then by the controller when it is extended. IN other words, CFrameWork::__construct() is created again everytime a controller method is reached. </p> <p>My questions: </p> <blockquote> <p>1) Does this have any harmful effect?</p> <p>2) Can this be avoided?</p> <p>3) Any suggestions on how you would do this differently?</p> </blockquote>
    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.
    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