dos71253 2015-10-30 14:47
浏览 138

如何访问在另一个PHP脚本类中声明的变量

I have a file called "Header.inc.php" which has two classes. HomepageHeader & Menu. Both classes have HTML inside a method. The problem is that I want to insert the menu in the HomepageHeader class but due to HTML I can't nor I don't know how to access the contents of another class in PHP.

Below is my code:

<?php

class HomepageHeader
{
    public $HomepageSlider = "HTML Code for Slider";

**At this point I want to insert the content of class**

//HTML Continues
}

class Menu
{
    public $PageMenu = "HTML Code for Menu";
}

The main objective is to insert the Menu class content between the HTML of the first class and then continue the HTML after that to make it one part.

  • 写回答

4条回答 默认 最新

  • drkj41932 2015-10-30 14:51
    关注

    My recommendation is you create a static variable and then access it without having to instantiate the class. Something like this:

    class Menu
    {
        public static $PageMenu = "HTML Code for Menu";
    }
    

    and then you can call it like this:

    print Menu::$PageMenu;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序