<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Johirul Islam</title>
    <description>The latest articles on DEV Community by Johirul Islam (@johirpro).</description>
    <link>https://dev.to/johirpro</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3778066%2F7dc327e1-4214-40f1-b4fe-1312ecd6b1ea.jpg</url>
      <title>DEV Community: Johirul Islam</title>
      <link>https://dev.to/johirpro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johirpro"/>
    <language>en</language>
    <item>
      <title>How does #PHP automatically find your classes without endless require() statements?

In Part 05 of my “Build Your Own PHP Framework from Scratch” series, I’m exploring #Composer, #PSR-4 #autoloading, controllers, and unified error/exception handling.</title>
      <dc:creator>Johirul Islam</dc:creator>
      <pubDate>Wed, 30 Sep 2026 15:35:53 +0000</pubDate>
      <link>https://dev.to/johirpro/how-does-php-automatically-find-your-classes-without-endless-require-statements-in-part-05-2859</link>
      <guid>https://dev.to/johirpro/how-does-php-automatically-find-your-classes-without-endless-require-statements-in-part-05-2859</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/johirpro/part-05-composer-2cio" class="crayons-story__hidden-navigation-link"&gt;Part 05 - Composer&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/johirpro" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3778066%2F7dc327e1-4214-40f1-b4fe-1312ecd6b1ea.jpg" alt="johirpro profile" class="crayons-avatar__image" width="713" height="581"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/johirpro" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Johirul Islam
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Johirul Islam
                
                
              
              &lt;div id="story-author-preview-content-4767650" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/johirpro" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3778066%2F7dc327e1-4214-40f1-b4fe-1312ecd6b1ea.jpg" class="crayons-avatar__image" alt="" width="713" height="581"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Johirul Islam&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/johirpro/part-05-composer-2cio" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Sep 30&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/johirpro/part-05-composer-2cio" id="article-link-4767650"&gt;
          Part 05 - Composer
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/composer"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;composer&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/errors"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;errors&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/exception"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;exception&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/packages"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;packages&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/johirpro/part-05-composer-2cio#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>backend</category>
      <category>php</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Part 05 - Composer</title>
      <dc:creator>Johirul Islam</dc:creator>
      <pubDate>Wed, 30 Sep 2026 02:28:06 +0000</pubDate>
      <link>https://dev.to/johirpro/part-05-composer-2cio</link>
      <guid>https://dev.to/johirpro/part-05-composer-2cio</guid>
      <description>&lt;p&gt;&lt;strong&gt;Source Code Files of this Chapter&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-root/
├── app/
│&amp;nbsp;&amp;nbsp; ├── Controllers/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── HomeController.php      # new file
│&amp;nbsp;&amp;nbsp; └── Core/
│&amp;nbsp;&amp;nbsp;     └── Bootstrap.php           # modified file
├── public/
│ &amp;nbsp;&amp;nbsp; └── index.php                  # modified file
│
├── vendor/                         # new directory
│
├── composer.json                   # new file
├── composer.lock                   # new file
└── .gitignore                      # new file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Using Composer
&lt;/h2&gt;

&lt;p&gt;This project is using core php that means no php package will be used. So someone may be surprised that why we are configuring composer? &lt;/p&gt;

&lt;p&gt;The answer in a single word is &lt;strong&gt;autoload&lt;/strong&gt;. Autoload will load required PHP classes based on their namespace and directory structure without using the &lt;code&gt;require()&lt;/code&gt; or &lt;code&gt;include()&lt;/code&gt; statement. &lt;/p&gt;
&lt;h2&gt;
  
  
  Configure Composer
&lt;/h2&gt;

&lt;p&gt;Go to the project root directory and run following command:&lt;br&gt;&lt;br&gt;
&lt;code&gt;composer init&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Above command will create a &lt;code&gt;composer.json&lt;/code&gt; file in the project root directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit &lt;code&gt;composer.json&lt;/code&gt; file:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"leafvein/own-framework-php-core-oop"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Create Own Framework Using PHP Core OOP"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"project"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"require"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"php"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;=8.0"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"autoload"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"psr-4"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"App\\"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"app/"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"minimum-stability"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"MIT"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Code Explain:&lt;/strong&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://getcomposer.org/doc/04-schema.md#name" rel="noopener noreferrer"&gt;name&lt;/a&gt; : a required attribute that is used as a unique identifier of the application within the composer ecosystem. composer.&lt;br&gt;&lt;br&gt;
&lt;a href="https://getcomposer.org/doc/04-schema.md#description" rel="noopener noreferrer"&gt;description&lt;/a&gt;: a short description of the package.&lt;br&gt;&lt;br&gt;
&lt;a href="https://getcomposer.org/doc/04-schema.md#require" rel="noopener noreferrer"&gt;require&lt;/a&gt;: another required attribute used to specify your project's  dependencies. Current now our project dependency is php 8.&lt;br&gt;&lt;br&gt;
&lt;a href="https://getcomposer.org/doc/04-schema.md#autoload" rel="noopener noreferrer"&gt;autoload&lt;/a&gt;: configure the method to load PHP classes and files of a project automatically. Here &lt;a href="https://getcomposer.org/doc/04-schema.md#psr-4" rel="noopener noreferrer"&gt;PSR-4&lt;/a&gt; is used to map namespace &lt;code&gt;App&lt;/code&gt; to &lt;code&gt;app&lt;/code&gt; directory.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Install Dependency and Generate Autoload File
&lt;/h2&gt;

&lt;p&gt;From your project-root directory run this command:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After running &lt;code&gt;composer install&lt;/code&gt; command composer will read project dependencies from the &lt;code&gt;composer.json&lt;/code&gt; file then create &lt;code&gt;vendor&lt;/code&gt; directory and &lt;code&gt;composer.lock&lt;/code&gt; file to the project root directory.  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;vendor&lt;/code&gt;: directory stores dependencies and &lt;a href="https://getcomposer.org/doc/01-basic-usage.md#autoloading" rel="noopener noreferrer"&gt;autoload.php&lt;/a&gt; file.&lt;br&gt;&lt;br&gt;
&lt;code&gt;composer.lock&lt;/code&gt;: file locks version of all dependencies to make an option so that all team members can use the same versions of dependencies.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Integrate the &lt;code&gt;autoload.php&lt;/code&gt; File into the Application
&lt;/h2&gt;

&lt;p&gt;We are integrating &lt;code&gt;vendor/autoload.php&lt;/code&gt; file through the Bootstrap. So, open the &lt;code&gt;app/Core/Bootstrap.php&lt;/code&gt; file and add this line:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../../vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;/p&gt;
  See full code: &lt;code&gt;app/Core/Bootstrap.php&lt;/code&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../../vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// load environment&lt;/span&gt;
&lt;span class="nv"&gt;$config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'PHP core OOP project'&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// route define&lt;/span&gt;
&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;ltrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"get-error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// trigger a fatal error&lt;/span&gt;
    &lt;span class="nb"&gt;trigger_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"An Intentional Error Occurred."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;E_USER_ERROR&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'get-exception'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// throw an exception&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"An Intentional Exception Occurred."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Welcome to the '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Load a Controller Class Using Composer Autoload
&lt;/h2&gt;

&lt;p&gt;Create a new &lt;code&gt;app/Controllers/HomeController.php&lt;/code&gt; file and add following code:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Controllers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HomeController&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$appName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$appName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;appName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$appName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getGreeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Welcome to the '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;appName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Code Explain&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A new Controller Class file is created, now it is require to update classmap of composer autoload. So, run following command: &lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer dump-autoload
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This command will update classmap of composer autoload to ensure all latest classes are available to use.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now you will be able to call the controller's method from the bootstrap. Open the &lt;code&gt;app/Core/Bootstrap.php&lt;/code&gt; file and add the following code:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Controllers\HomeController&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$homeController&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HomeController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$homeController&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getGreeting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Code Explain&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;

&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Controllers\HomeController&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Loading HomeController class using fully qualified class names (FQCNs)&lt;/p&gt;


&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$homeController&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HomeController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$homeController&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getGreeting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Instantiation of HomeController class and Displaying content of the getGreeting()&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;
  See full code: &lt;code&gt;app/Core/Bootstrap.php&lt;/code&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../../vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Controllers\HomeController&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// load environment&lt;/span&gt;
&lt;span class="nv"&gt;$config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'PHP core OOP project'&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// route define&lt;/span&gt;
&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;ltrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"get-error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// trigger a fatal error&lt;/span&gt;
    &lt;span class="nb"&gt;trigger_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"An Intentional Error Occurred."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;E_USER_ERROR&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'get-exception'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// throw an exception&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"An Intentional Exception Occurred."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;$homeController&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HomeController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$homeController&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getGreeting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Unified Error and Exception Handler
&lt;/h2&gt;

&lt;p&gt;On chapter 03 we've used &lt;code&gt;set_error_handler()&lt;/code&gt; and &lt;code&gt;set_exception_handler()&lt;/code&gt; to handle error and exception respectively. In this chapter we will use try-catch statement to simplify the Error and Exception Handling.&lt;br&gt;
Open the &lt;code&gt;public/index.php&lt;/code&gt; file and modify as below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;- // error handler
- set_error_handler(function ($errno, $errstr, $errfile, $errline) {
-    echo 'Message: ' . $errno   . ' - ' . $errstr . '&amp;lt;br&amp;gt;';
-    echo 'File: '    . $errfile . '&amp;lt;br&amp;gt;';
-    echo 'Line: '    . $errline . '&amp;lt;br&amp;gt;';
- });
-
- // exception handler
- set_exception_handler(function (Exception $e) {
-     echo 'Message: ' . $e-&amp;gt;getMessage() . '&amp;lt;br&amp;gt;';
-     echo 'File: '    . $e-&amp;gt;getFile()    . '&amp;lt;br&amp;gt;';
-     echo 'Line: '    . $e-&amp;gt;getLine()    . '&amp;lt;br&amp;gt;';
-});
-
&lt;/span&gt;&lt;span class="gi"&gt;+ try {
&lt;/span&gt;    require __DIR__ . '/../app/Core/Bootstrap.php';
&lt;span class="gi"&gt;+ } catch (Throwable $e) {
+    echo 'Message: ' . $e-&amp;gt;getMessage() . '&amp;lt;br&amp;gt;';
+    echo 'File: '    . $e-&amp;gt;getFile()    . '&amp;lt;br&amp;gt;';
+    echo 'Line: '    . $e-&amp;gt;getLine()    . '&amp;lt;br&amp;gt;';
+}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Code Explain&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead of handling Error and Exception separately we are using unified handler &lt;code&gt;Throwable&lt;/code&gt;. In PHP 7 and later, a single try-catch block can catch both traditional exceptions and critical internal PHP errors.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;
  See full code: &lt;code&gt;public/index.php&lt;/code&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../app/Core/Bootstrap.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Throwable&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Message: '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'File: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getFile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Line: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getLine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Result
&lt;/h2&gt;

&lt;p&gt;Make sure server is running or go to the project-root directory and run command &lt;code&gt;php -S localhost:8000 -t public/&lt;/code&gt; on the terminal.    &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browse &lt;code&gt;http://localhost:8000&lt;/code&gt; -&amp;gt; Returns a welcome greeting message
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvob86uemimhnmts6j2ud.png" alt="output-result-1" width="800" height="424"&gt;
&lt;/li&gt;
&lt;li&gt;Browse: &lt;code&gt;http://localhost:8000/get-error&lt;/code&gt; -&amp;gt; It will return a 500 Internal Server Error.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7gl1u4vn6jz0slmmd9ay.png" alt="output-result-2" width="800" height="424"&gt;
However, if you check the terminal, you will see more information about what caused the error. 
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvk05jx7zpkpfqwts5rlz.png" alt="output-result-3" width="800" height="525"&gt;
&lt;div class="crayons-card c-embed"&gt;

  
In PHP, errors and exceptions are different concepts, and there are several ways to throw, catch, and handle exceptions and errors.&lt;br&gt;
In the next part, &lt;strong&gt;Part 06 — Error and Exception&lt;/strong&gt;, we’ll discuss errors and exceptions in PHP in more detail.

&lt;/div&gt;


&lt;/li&gt;

&lt;li&gt;Browse: &lt;code&gt;&lt;a href="http://localhost:8000/get-exception" rel="noopener noreferrer"&gt;http://localhost:8000/get-exception&lt;/a&gt;&lt;/code&gt; -&amp;gt; Returns exception information 
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3pvwj941p39mw5urrlr7.png" alt="output-result-4" width="800" height="424"&gt;
&lt;h2&gt;
  
  
  Git : Add &lt;code&gt;.gitignore&lt;/code&gt; File and Push Changes to Remote&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;If testing result is satisfactory then it is time to push changes to the remote repository.&lt;br&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Run Command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As expected you will see the &lt;code&gt;vendor&lt;/code&gt; directory in untracked stage but it is &lt;a href="https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md" rel="noopener noreferrer"&gt;not recommended to push the &lt;code&gt;vendor&lt;/code&gt; directory to the remote repository&lt;/a&gt;. In Git terminology, this is called 'ignore or not track'. Git uses &lt;code&gt;.gitignore&lt;/code&gt; file to ignore directory and files.&lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;.gitignore&lt;/code&gt; file on project-root directory with following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/vendor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the files that are newly created in this chapter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git add HomeController.php composer.json composer.lock .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git add &amp;lt;file_path&amp;gt;&lt;/code&gt; command add specific file content to the staging area for the next commit. We are adding &lt;code&gt;HomeController.php&lt;/code&gt;, &lt;code&gt;composer.json&lt;/code&gt;, &lt;code&gt;.gitignore&lt;/code&gt;, and &lt;code&gt;composer.lock&lt;/code&gt; files to the staging area for next commit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;⚠️ &lt;code&gt;composer.lock&lt;/code&gt;! 🤔. Yes, &lt;a href="https://getcomposer.org/doc/01-basic-usage.md#installing-from-composer-lock" rel="noopener noreferrer"&gt;commit your composer.lock file to git repository&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
⚠️ &lt;code&gt;.gitignore&lt;/code&gt;! 🤔 🤔. Yes, yes, Commit the &lt;code&gt;.gitignore&lt;/code&gt; file to ensure everyone using the repository ignores the same files.&lt;/p&gt;

&lt;p&gt;Add the files that are modified in this chapter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git add &lt;span class="nt"&gt;-p&lt;/span&gt; Bootstrap.php
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git add &lt;span class="nt"&gt;-p&lt;/span&gt; index.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;💡 &lt;code&gt;git add -p &amp;lt;file_path&amp;gt;&lt;/code&gt; command provides an review option that steps through each hunk (section of changes) in the specified filename and asks you whether you want to stage that specific hunk or not. To add specific section of changes just type &lt;code&gt;y&lt;/code&gt; otherwise &lt;code&gt;n&lt;/code&gt;. It will prevent you to add any unintentional testing code and it your code will clean.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Commit your changes and push to the remote repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Configured composer"&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git push origin &amp;lt;branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Learn More
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://getcomposer.org/download/" rel="noopener noreferrer"&gt;Install Composer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getcomposer.org/doc/04-schema.md" rel="noopener noreferrer"&gt;Composer JSON schema (properties)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.php-fig.org/psr/psr-4/" rel="noopener noreferrer"&gt;PSR-4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/git/git_ignore.asp" rel="noopener noreferrer"&gt;.gitignore&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/leafvein/own-framework-php-core-oop/blob/master/source_code/05" rel="noopener noreferrer"&gt;⬇SOURCE CODE: Chapter 05&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>composer</category>
      <category>errors</category>
      <category>exception</category>
      <category>packages</category>
    </item>
    <item>
      <title>Part 04 - Configure Git for Collaboration</title>
      <dc:creator>Johirul Islam</dc:creator>
      <pubDate>Wed, 30 Sep 2026 02:27:41 +0000</pubDate>
      <link>https://dev.to/johirpro/part-04-configure-git-for-collaboration-27ic</link>
      <guid>https://dev.to/johirpro/part-04-configure-git-for-collaboration-27ic</guid>
      <description>&lt;p&gt;&lt;strong&gt;Source Code Files of this Chapter&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-root/
├── app/
│&amp;nbsp;&amp;nbsp; └── Core/
│&amp;nbsp;&amp;nbsp;     └── Bootstrap.php
├── .git/                                   # new directory
└── public/
    └── index.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Git
&lt;/h2&gt;

&lt;p&gt;We are in the very initial stages of a framework creation. Now it is time to configure git.&lt;/p&gt;

&lt;p&gt;You are creating a framework, right! So Git will be a handful tool for collaborating with colleagues, teams, or friends, or for sharing code by embedding it in blog posts.&lt;/p&gt;

&lt;p&gt;Do you have any account of git cloud repository hosting like &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; or any other? If not, just create an account and it is free.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure Git on Local
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Go to the project root&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;project_root&amp;gt; 

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git init

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git add &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial commit"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure Git on Remote
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository" rel="noopener noreferrer"&gt;Create a new repository on the github and configure&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the remote repository url&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Push Changes to GitHub
&lt;/h2&gt;

&lt;p&gt;To make a connection between your local and remote repository first of all you have to set the remote origin. So, set the remote repository url as a remote origin and push changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Go to the project root&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git remote add origin &amp;lt;remote_repository_URL&amp;gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin &amp;lt;branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ⚠️ Important
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Github uses SSH Key to establish a connection between your local machine and &lt;code&gt;github.com&lt;/code&gt;. You have to &lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent" rel="noopener noreferrer"&gt;generate SSH key to your local machine&lt;/a&gt; if it is not exist and &lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account" rel="noopener noreferrer"&gt;add to your github account&lt;/a&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Result
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Go to your remote repository and you will see your source code is uploaded.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Learn More
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git" rel="noopener noreferrer"&gt;Install Git&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/git-guides/git-add" rel="noopener noreferrer"&gt;git add&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/git/git_commit.asp" rel="noopener noreferrer"&gt;git commit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codecademy.com/learn/fscp-git-and-github-part-ii/modules/fscp-git-branching/cheatsheet" rel="noopener noreferrer"&gt;git branch&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/leafvein/own-framework-php-core-oop/blob/master/source_code/04" rel="noopener noreferrer"&gt;⬇SOURCE CODE: Chapter 04&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>git</category>
      <category>github</category>
      <category>webdev</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Johirul Islam</dc:creator>
      <pubDate>Sat, 26 Sep 2026 07:24:27 +0000</pubDate>
      <link>https://dev.to/johirpro/-3f25</link>
      <guid>https://dev.to/johirpro/-3f25</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/johirpro/part-03-bootstrap-4iof" class="crayons-story__hidden-navigation-link"&gt;Part 03 - Bootstrap&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/johirpro" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3778066%2F7dc327e1-4214-40f1-b4fe-1312ecd6b1ea.jpg" alt="johirpro profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/johirpro" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Johirul Islam
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Johirul Islam
                
                
              
              &lt;div id="story-author-preview-content-4744038" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/johirpro" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3778066%2F7dc327e1-4214-40f1-b4fe-1312ecd6b1ea.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Johirul Islam&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/johirpro/part-03-bootstrap-4iof" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Sep 26&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/johirpro/part-03-bootstrap-4iof" id="article-link-4744038"&gt;
          Part 03 - Bootstrap
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/php"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;php&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/developer"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;developer&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/learning"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;learning&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/johirpro/part-03-bootstrap-4iof#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            3 min read
          &lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Part 03 - Bootstrap</title>
      <dc:creator>Johirul Islam</dc:creator>
      <pubDate>Sat, 26 Sep 2026 06:15:08 +0000</pubDate>
      <link>https://dev.to/johirpro/part-03-bootstrap-4iof</link>
      <guid>https://dev.to/johirpro/part-03-bootstrap-4iof</guid>
      <description>&lt;h2&gt;
  
  
  Prepare Runnable Environment by Loading Common Dependencies
&lt;/h2&gt;

&lt;p&gt;When a client’s request comes to the front controller, we want to pass the request through a middle layers instead of directly starting the process. That’s why we need the Bootstrap that will load configuration data, request information, (autoload) classes and if required it could be response for exception.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source Code Files of this Chapter&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-root/
├── app/
│&amp;nbsp;&amp;nbsp; └── Core/
│&amp;nbsp;&amp;nbsp;     └── Bootstrap.php                   # new file
└── public/
    └── index.php                           # modified file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create &lt;code&gt;Bootstrap.php&lt;/code&gt; File
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;app/Core/Bootstrap.php&lt;/code&gt; file and write following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// load environment&lt;/span&gt;
&lt;span class="nv"&gt;$config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'PHP core OOP project'&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// route define&lt;/span&gt;
&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;ltrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"get-error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// trigger a fatal error&lt;/span&gt;
    &lt;span class="nb"&gt;trigger_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"An Intentional Error Occurred."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;E_USER_ERROR&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'get-exception'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// throw an exception&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"An intentional Exception Occurred."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Welcome to the '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Explain:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;

&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;As we explained in &lt;a href="//02-front-controller.md"&gt;Front Controller index.php file&lt;/a&gt; chapter, the &lt;code&gt;declare(strict_types=1)&lt;/code&gt; cannot be set globally for the whole project It only works per file and should be placed at the top of every PHP file.&lt;/p&gt;


&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;ltrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"get-error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// trigger a fatal error&lt;/span&gt;
   &lt;span class="nb"&gt;trigger_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"An Intentional Error Occurred."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;E_USER_ERROR&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$route&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'get-exception'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// throw an exception&lt;/span&gt;
   &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"An intentional Exception Occurred.&amp;gt; "&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Get the route path using Global &lt;code&gt;$_SERVER&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;Based on the route triggered error and thrown exception intentionally using a hard-coded condition&lt;/p&gt;


&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
   &lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'PHP core OOP project'&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Welcome to the '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app_name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Using static configuration variable, displaying a welcome greeting message.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Inject Bootstrap into Front Controller
&lt;/h2&gt;

&lt;p&gt;The front controller will only receive the request and will not contain any application logic or data. Open the &lt;code&gt;public/index.php&lt;/code&gt; file in editor and update the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../app/Core/Bootstrap.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Explain:&lt;/strong&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;First, load and execute the bootstrap file into the front-controller.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Bootstrap injecting in the front-controller is done, now we will add the following code to the front-controller file to handle the errors and exceptions that we conditionally triggered in the bootstrap file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// error handler&lt;/span&gt;
&lt;span class="nb"&gt;set_error_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$errno&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$errstr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$errfile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$errline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Message: '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$errno&lt;/span&gt;   &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;' - '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$errstr&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'File: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$errfile&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Line: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$errline&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// exception handler&lt;/span&gt;
&lt;span class="nb"&gt;set_exception_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Exception&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Message: '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'File: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getFile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Line: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getLine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Explain:&lt;/strong&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When an error occurs in the application, &lt;code&gt;set_error_handler()&lt;/code&gt; will be called and it will display information about the error.&lt;/p&gt;

&lt;p&gt;When an exception occurs in the application, &lt;code&gt;set_exception_handler()&lt;/code&gt; will be called and it will display information about the exception.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;
  See full code: &lt;code&gt;public/index.php&lt;/code&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// error handler&lt;/span&gt;
&lt;span class="nb"&gt;set_error_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$errno&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$errstr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$errfile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$errline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Message: '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$errno&lt;/span&gt;   &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;' - '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$errstr&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'File: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$errfile&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Line: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$errline&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// exception handler&lt;/span&gt;
&lt;span class="nb"&gt;set_exception_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Exception&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Message: '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'File: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getFile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Line: '&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getLine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;    &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;br&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../app/Core/Bootstrap.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Result
&lt;/h2&gt;

&lt;p&gt;Make sure server is running or go to the project-root directory and run command &lt;code&gt;php -S localhost:8000 -t public/&lt;/code&gt; on the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkd9e6ce6vb78cwdbuuqo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkd9e6ce6vb78cwdbuuqo.png" alt="command" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browse &lt;code&gt;http://localhost:8000&lt;/code&gt; -&amp;gt; Returns a welcome greeting message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpsw0dos1dfzp2evryptm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpsw0dos1dfzp2evryptm.png" alt="output-result-1" width="796" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browse: &lt;code&gt;http://localhost:8000/get-error&lt;/code&gt; -&amp;gt; Returns error information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxe54nz4y79mwg68dxs1j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxe54nz4y79mwg68dxs1j.png" alt="output-result-2" width="796" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browse: &lt;code&gt;http://localhost:8000/get-exception&lt;/code&gt; -&amp;gt; Returns exception information &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn0ubtoc09w80azjg4v71.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn0ubtoc09w80azjg4v71.png" alt="output-result-3" width="796" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn More
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/swyx/errors-are-not-exceptional-1g0b"&gt;PHP's error are not exception&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.php.net/manual/en/function.trigger-error.php" rel="noopener noreferrer"&gt;trigger_error()&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/php/php_exception.asp" rel="noopener noreferrer"&gt;Throwing exception&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/leafvein/own-framework-php-core-oop/blob/master/source_code/03" rel="noopener noreferrer"&gt;⬇SOURCE CODE: Chapter 03&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>developer</category>
      <category>learning</category>
    </item>
    <item>
      <title>Part 02 - Front Controller (index.php) File</title>
      <dc:creator>Johirul Islam</dc:creator>
      <pubDate>Sat, 26 Sep 2026 06:14:08 +0000</pubDate>
      <link>https://dev.to/johirpro/part-02-front-controller-indexphp-file-5cjf</link>
      <guid>https://dev.to/johirpro/part-02-front-controller-indexphp-file-5cjf</guid>
      <description>&lt;p&gt;&lt;strong&gt;Source Code Files of this Chapter:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-root/
└── public/
   └──index.php                             # new file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Front Controller Design Pattern
&lt;/h2&gt;

&lt;p&gt;Front controller is a central (obviously a single) entry point to handle incoming client request.&lt;/p&gt;

&lt;p&gt;To implement front controller design pattern in this project, our central entry point will be an &lt;code&gt;index.php&lt;/code&gt; file. So let's create an &lt;code&gt;index.php&lt;/code&gt; file in the public directory. We have chosen to create the &lt;code&gt;index.php&lt;/code&gt; file in the &lt;code&gt;public&lt;/code&gt; directory instead of the project root directory because we want to protect our project’s confidential and sensitive code from publicly access. This access restriction could be implemented by setting file permission, and off course we will do this but also separate public resources so that no one can access the rest of the project except the public resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Front Controller
&lt;/h2&gt;

&lt;p&gt;Now open the &lt;code&gt;public/index.php&lt;/code&gt; file, write the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Welcome to the PHP core OOP Project!'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Explain:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;

&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;code&gt;declare(strict_types=1)&lt;/code&gt; enforces strict type checking for function arguments and return values within a specific PHP file. Only exact type of the type declaration will be accepted, or a TypeError will be thrown. &lt;/p&gt;

&lt;p&gt;Unfortunately, in a projects, &lt;code&gt;declare(strict_types=1)&lt;/code&gt; cannot be set globally for the whole project It only works per file and should be placed at the top of every PHP file.&lt;/p&gt;


&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Welcome to the PHP core OOP Project!'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Show this string text on the browser screen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Result
&lt;/h2&gt;

&lt;p&gt;If the local server and domain hosting configured properly, then it is time to check the result of your first code. Let’s say your local domain is &lt;code&gt;http://localhost:8000&lt;/code&gt;. So, browse this URL, expected result is &lt;code&gt;Welcome to the PHP core OOP Project!&lt;/code&gt;. If there is an exception, look at the error code number and debug accordingly. And if necessary, you can view the server log.&lt;/p&gt;

&lt;h3&gt;
  
  
  💡 Tip : Local Server Setup
&lt;/h3&gt;

&lt;p&gt;You can use any of LAMP, MAMP, WAMP or XAMPP Stack as a local server. I've used PHP's built in server to develop this project.   &lt;/p&gt;

&lt;p&gt;Open terminal/shell then run commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;project-root&amp;gt; 
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; php &lt;span class="nt"&gt;-S&lt;/span&gt; localhost:8000 &lt;span class="nt"&gt;-t&lt;/span&gt; public/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F23xxmvmgwjcyz0uq47n8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F23xxmvmgwjcyz0uq47n8.png" alt="commands" width="800" height="346"&gt;&lt;/a&gt;&lt;br&gt;
Now browse: &lt;code&gt;http://localhost:8000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F25d2eejscdibg41p8ann.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F25d2eejscdibg41p8ann.png" alt="result" width="796" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn More
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Page controller:  &lt;br&gt;While the Front Controller pattern provides a single, centralized entry point for all requests in an application, the Page Controller is an architectural approach where each individual page request has its own controller and this controller is primary handler for its request. It is responsible for handling the logic associated with that particular page or request.&lt;br&gt;
Advantages of front controller against page controller&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In addition to the PHP application, the &lt;a href="https://dev.to/xxzeroxx/php-design-patterns-front-controller-jjo"&gt;front controller needs to be configured on the server end&lt;/a&gt; as well.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/leafvein/own-framework-php-core-oop/blob/master/source_code/02" rel="noopener noreferrer"&gt;⬇SOURCE CODE: Chapter 02&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>Part 01 - Directory Structure of the Application</title>
      <dc:creator>Johirul Islam</dc:creator>
      <pubDate>Sat, 26 Sep 2026 06:13:19 +0000</pubDate>
      <link>https://dev.to/johirpro/part-01-directory-structure-of-the-application-44hb</link>
      <guid>https://dev.to/johirpro/part-01-directory-structure-of-the-application-44hb</guid>
      <description>&lt;p&gt;&lt;strong&gt;Source Code Files of this Chapter&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-root/
│── public/
│
└── app/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;/p&gt;
  See the final project directory structure
  &lt;pre&gt;&lt;code&gt;
project-root
├── app/
│&amp;nbsp;&amp;nbsp; ├── Controllers/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Api/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── UserController.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── AuthController.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── EmailVerificationController.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── HomeController.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── UserController.php
│&amp;nbsp;&amp;nbsp; ├── Core/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Abstract/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Migration.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Model.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── Seeder.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── App.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Bootstrap.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Config.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Database.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Env.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── ExceptionHandler.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Mailer.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Request.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Response.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Router.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── Validator.php
│&amp;nbsp;&amp;nbsp; ├── Helpers/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── helpers.php
│&amp;nbsp;&amp;nbsp; ├── Models/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── EmailQueue.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── EmailVerification.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── User.php
│&amp;nbsp;&amp;nbsp; ├── Queue/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── MailQueue.php
│&amp;nbsp;&amp;nbsp; └── Services/
│&amp;nbsp;&amp;nbsp;     └── EmailVerificationService.php
├── composer.json
├── composer.lock
├── config/
│&amp;nbsp;&amp;nbsp; ├── app.php
│&amp;nbsp;&amp;nbsp; ├── database.php
│&amp;nbsp;&amp;nbsp; └── mail.php
├── database/
│&amp;nbsp;&amp;nbsp; ├── Migrations/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── 2026_01_10_create_users_table.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── 2026_01_18_create_email_queue_table.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── 2026_01_18_create_email_verifications_table.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── 2026_01_19_add_password_to_users_table.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── 2026_01_19_add_verified_column_to_users_table.php
│&amp;nbsp;&amp;nbsp; └── Seeders/
│&amp;nbsp;&amp;nbsp;     └── UserSeeder.php
├── .env
├── .env.testing
├── .gitignore
├── migration.php
├── .phpunit.result.cache
├── phpunit.xml
├── public/
│&amp;nbsp;&amp;nbsp; ├── adminer.php
│&amp;nbsp;&amp;nbsp; ├── css/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── style.css
│&amp;nbsp;&amp;nbsp; ├── images/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── welcome.png
│&amp;nbsp;&amp;nbsp; ├── index.php
│&amp;nbsp;&amp;nbsp; └── scripts/
│&amp;nbsp;&amp;nbsp;     └── app.js
├── queue.php
├── routes/
│&amp;nbsp;&amp;nbsp; ├── api.php
│&amp;nbsp;&amp;nbsp; └── web.php
├── seeder.php
├── server.php
├── tests/
│&amp;nbsp;&amp;nbsp; ├── Bootstrap.php
│&amp;nbsp;&amp;nbsp; ├── Database/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── DatabaseConnectionTest.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── MigrationTest.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── Seeders/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── UserSeeder.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; ├── SeederTest.php
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── UserModelTest.php
│&amp;nbsp;&amp;nbsp; ├── DatabaseTestCase.php
│&amp;nbsp;&amp;nbsp; ├── Feature/
│&amp;nbsp;&amp;nbsp; │&amp;nbsp;&amp;nbsp; └── HomePageTest.php
│&amp;nbsp;&amp;nbsp; └── Unit/
│&amp;nbsp;&amp;nbsp;     ├── ConfigTest.php
│&amp;nbsp;&amp;nbsp;     ├── EnvTest.php
│&amp;nbsp;&amp;nbsp;     ├── RequestTest.php
│&amp;nbsp;&amp;nbsp;     ├── RouterTest.php
│&amp;nbsp;&amp;nbsp;     └── ValidatorTest.php
├── vendor/
└── views/
    ├── auth/
    │&amp;nbsp;&amp;nbsp; └── login.php
    ├── home.php
    ├── layout.php
    └── user/
        ├── edit.php
        ├── register.php
        └── show.php
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;&lt;/p&gt;



&lt;p&gt;The directory structure is the skeleton of the project. So the more standardized and understandable it can be,  the project will be in terms of extensible, maintainable, and testable.&lt;/p&gt;

&lt;h2&gt;
  
  
  MVC-inspired Directory Structure
&lt;/h2&gt;

&lt;p&gt;On this project, the directory structure is flexible and conventional. Which means you can create it the way you want. But since the PHP community has been using different directory structures in web development for a long time, some conventions have become well-known regarding the names and patterns of files and directories. For example, &lt;code&gt;src&lt;/code&gt;, &lt;code&gt;config&lt;/code&gt;, &lt;code&gt;.env&lt;/code&gt;, &lt;code&gt;public&lt;/code&gt;, &lt;code&gt;index.php&lt;/code&gt; etc. &lt;/p&gt;

&lt;p&gt;Our project will be like MVC and we will use &lt;code&gt;PSR-4&lt;/code&gt; through Composer for class autoloader. &lt;/p&gt;

&lt;h2&gt;
  
  
  Init Coding
&lt;/h2&gt;

&lt;p&gt;So, let’s start to build the &lt;code&gt;project-root&lt;/code&gt; directory first, then create &lt;code&gt;public&lt;/code&gt; and &lt;code&gt;app&lt;/code&gt; directory inside the &lt;code&gt;project-root&lt;/code&gt; directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;mkdir&lt;/span&gt; &amp;lt;PROJECT_NAME&amp;gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;PROJECT_NAME&amp;gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;mkdir &lt;/span&gt;public app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;PROJECT_NAME&amp;gt;&lt;/code&gt;: your project name, it will be the &lt;code&gt;project-root&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;public&lt;/code&gt;: the default accessible file of the project&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app&lt;/code&gt;: all project related class will go here&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftm0lezwon2oaowolj914.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftm0lezwon2oaowolj914.png" alt="command" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/leafvein/own-framework-php-core-oop/blob/master/source_code/01" rel="noopener noreferrer"&gt;⬇SOURCE CODE: Chapter 01&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>learning</category>
    </item>
    <item>
      <title>Introduction</title>
      <dc:creator>Johirul Islam</dc:creator>
      <pubDate>Sat, 26 Sep 2026 06:11:57 +0000</pubDate>
      <link>https://dev.to/johirpro/introduction-1cdh</link>
      <guid>https://dev.to/johirpro/introduction-1cdh</guid>
      <description>&lt;p&gt;Over the time, PHP and its various tools have become more advanced and easier to use. As a result, you can create your own framework even using core PHP. Although there are many reputable, well-known, secure, updated and well-documented open source PHP frameworks that can be easily installed and used with Git or Composer commands. But as a PHP learner, if you want to understand how things like function classes, namespace objects, and so on work together within a framework, there is no substitute for hands-on learning.&lt;/p&gt;

&lt;p&gt;So let's start by building a simple framework from scratch.&lt;/p&gt;

&lt;p&gt;Please keep in mind that we are not inventing anything new. We will just use various functions and features of PHP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;This framework is for learning purposes only. It is not intended for professional use or use on production server.&lt;/li&gt;
&lt;li&gt;This tutorial is not for novice in PHP. You should have at least an understanding of object-oriented programming concepts. It is also recommended to have a grasp of MVC and Solid Design Patterns.&lt;/li&gt;
&lt;li&gt;Highly recommend to get clear knowledge about git and composer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>developer</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
