dpnof28482 2013-04-04 19:00
浏览 22

来自变量的PHP类名

Can I dynamically name a class?

I have written a process which calls about 6 pages that generate pdfs through tcpdf. They all use the same header page which makes a class.

class myPDF extends TCPDF {

the problem is when i run my script I get Fatal error: Cannot redeclare class myPDF in after the first page is done.

I understand why but am at a loss how to deal with it.

calling it only once is no good as it holds a function which looks at page specific variables.

I also don't think I can UNdeclare it in anyway.

Once way would be to change the class name for each include but not sure how to make the class name a variable?

ie class $newname

Any ideas

S

Added this

class myPDF extends TCPDF {
public function Header () {

global $title;
global $client;
global $host;


$oMulticell->multiCell(266,8, "<s1>$title&nbsp;     Client:</s1> <s2>$client</s2>     <s1>Host:</s1> <s2>$host</s2>     <s1>Currency:</s1> <s2>$currency</s2>     <s1>Reporting Period:</s1> <s2>$start_date_rep to $end_date_rep</s2>", 'TB');
}
  • 写回答

2条回答 默认 最新

  • douxian7534 2013-04-04 19:11
    关注

    You can't. Class definition has to be parsable in compile-time, and not in run-time. You can't make a "dynamic" class name.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?