douchun6108 2011-07-28 13:45
浏览 34
已采纳

动态PHP子类名

I've a really easy Php question.

Is the following possible:

$foo = 'bar';
Class $foo extends Object
{
...
}

I believe any OOP developer will have an idea about what I wish to accomplish. Thanks in advance for any hints.

UPDATE: Sometimes you would want to have the script's filename as its own classname (of course you'll have to prefix the classname to minimize collission). Also... without using eval(). I should have written the code as:

$cls = 'MyCls' . basename(__FILE__);
Class $cls extends Object
{
...
}
  • 写回答

3条回答 默认 最新

  • doutan4831 2011-07-29 14:06
    关注

    I don't know what your specific requirements are, however, I think you are going the wrong way about it. Rather than trying to create the class name based on the file name, why not use __autolod() to load whatever the class you like and your code will know how to find it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析