Makes a navbar for a website with object oriented php I do this as sort of hobby and want to no if I can improve.
This is a simplified version of my code that normal works with bootstrap classes and id's.
At the bottom there is the input of the classes.
I have already a working version connected with SQL Database.
but want to take it a step further with object oriented php.

The next step for me is to create the content page underneath the navbar.
I work with a .htaccess file that redirects everything to index.php, and then use the URI to show the right content.

The main class

&lt;?php

class Main
{
  public $URL;
  public $PageName;
  public function __construct($PageName)
  {
    $this-&gt;PageName = $PageName;
    $this-&gt;URL = $_SERVER['REQUEST_URI'];
  }
  public static function header() {
    echo '&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    ...
  &lt;/head&gt;';
  }

  public static function navstart() {
    echo '&lt;body&gt;&lt;nav&gt;&lt;ul&gt;';
  }

  public static function navend() {
    echo '&lt;/ul&gt;&lt;/nav&gt;';
  }
}


the navitem class is for making the items in the nav bar&lt;br&gt;

class navItem extends Main
{

    public function __construct($PageName)
  {
    parent::__construct($PageName);
    $ActiveUrl = ($this-&gt;URL == "/".$this-&gt;PageName) ? " active " : " ";
    echo     '&lt;li class="nav-item"&gt;
      &lt;a class="nav-link'.$ActiveUrl.'" href="'.$this-&gt;PageName.'"&gt;'.$this-&gt;PageName.'&lt;/a&gt;&lt;/li&gt; &amp;nbsp;';
  }
}


The nav dropdown class to make the dropdown in the navbar

class navDropdown extends Main
{
  public function __construct($PageName, $Item)
  {
    parent::__construct($PageName);
    $shortURL = substr($this-&gt;URL, 0, strpos($this-&gt;URL, "_"));
    $ActiveUrl = ($shortURL == "/".$this-&gt;PageName) ? " active " : " ";
    echo '
      &lt;li class="nav-item dropdown "&gt;
        &lt;a class="nav-link'.$ActiveUrl.' href="#"&gt;'.$this-&gt;PageName.'&lt;/a&gt;
        &lt;div&gt;';
        foreach ($Item as $Item) {
          $ActiveUrl = ($this-&gt;URL == "/".$this-&gt;PageName.'_'.$Item) ? " active " : " ";
          echo '
          &lt;a class="dropdown-item'.$ActiveUrl.'" href="./'.$this-&gt;PageName.'_'.$Item.'" &gt;'.$Item.'&lt;/a&gt;';
        }
        echo '&lt;/div&gt;&lt;/li&gt; &amp;nbsp;';    
  }
}


the variables to make the page

main::header();
main::navstart();
$test = new navDropDown("test", array('test1' , 'test2', 'test3' , 'test4'));
$home = new navItem("home");
$about = new navItem("about");
$pages = new navDropDown("pages",array("one", "two", "three" ));
$contact = new navItem("contact");
main::navend();
I think you have some reading/research to do as I'm not sure you understand OOP...

What is Main?


Main is setup as a class, used as a namespace in instantiation, then extended(why?).
Generally in the context it seems to be intended to be used App or &lt;AppName&gt; are better options


When to extend


Why do all elements extend Main?


It appears to be solely for it's constructor which it never uses itself. (Extra Baggage in Main)
Main also only contains functions the other elements never need or use (Extra Baggage in the Sub-Objects)

Extending a class makes more sense if the classes extended from it share functionality


What even is an Object? ##


You seem to be using your objects as functions disguised as things.


For example: when you create a navItem:
You create the object
It's controller prints itself to the screen
You capture it in a variable never to be used again. Why?



Who gets to be an Object?


navItem is an object navBar Isn't
navDropdown is an object navDropdownItem isn't