Skip to main content
added 403 characters in body
Source Link
user1479891
  • 159
  • 1
  • 2
  • 15

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'); } 

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

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'); } 
Source Link
user1479891
  • 159
  • 1
  • 2
  • 15

PHP Class names from variables

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