Jump to content

PHP OOP ???


LEGEND383

Recommended Posts

Hi.  I have the following class definition on my site:

class Theme
{
  public $Title = string;
  public $CSS = string;
  public $LogoPath = string;
  public $NavMenuItems = array();

  public function OutputHeader()
  {
    // Output HTML header with $CSS and $Title
  }
  public function OutputTableHeader()
  {
    // Output table header with $Title, $LogoPath and $NavMenuItems
  }
  public function OutputFooter()
  {
    // Output footer that closes all tags
  }
}

When I try to use the following code to create and setup an instance of the class, I get the error: "Fatal error: Cannot access empty property".  I am fully aware that it is empty, and I am trying to assign it a value, so I don't understand why it matters whether it's empty before I assign the value to it?

$Themes = array();

// Assign values to $Title, $CSS, $LogoPath and $NMI (NavMenuItems)

$Themes["root"] = new Theme;
$Themes["root"]->$Title = $Title;
$Themes["root"]->$CSS = $CSS;
$Themes["root"]->$LogoPath = $LogoPath;
$Themes["root"]->$NavMenuItems = $NMI; // This line throws the error.

:wtf:

Link to comment
https://forums.phpfreaks.com/topic/227857-php-oop/
Share on other sites

Thanks for the reply ansharma.  I tried your sugestion, but ended up with "Fatal error: Cannot use [] for reading" (even though I'm still trying to ASSIGN a value, :wtf:)

 

I have also tried a foreach loop on $NMI, assigning all values to $Themes["root"]->$NavMenuItems[], but got the same error as above.

Link to comment
https://forums.phpfreaks.com/topic/227857-php-oop/#findComment-1174958
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.