Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you pass a variable to a class extension?
    primarykey
    data
    text
    <p>The concept of adding a variable to a class's extension is something I am not grasping and could use some help.</p> <p>This is an example of a class I am extending. It works great but I can't access the $XML variable. I could make $XML a global but I know to avoid doing that.</p> <pre><code>&lt;?php //Sample XML Object $XML = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt; &lt;data&gt;&lt;foo&gt;Bingo!&lt;/foo&gt;&lt;/data&gt;"; $XML = simplexml_load_string($XML); // Extend the class class myExt extends ENTERPRISE { public function HTMLBlock() { // Set font $this-&gt;SetFont('helvetica', 'B', 10); $html = ' &lt;P style="font-weight:normal;"&gt; This is a test text cell&lt;br /&gt; Foo is set to '.$XML-&gt;foo.' &lt;/P&gt; '; // Title $this-&gt;htmlToBlock(90, '200', $HTML ); } } $pdf = new myExt('L', 'Letter', 'Landscape', true, 'UTF-8', false); ?&gt; </code></pre> <p>I have read about constructs. I know I need to add to the parent construct, I still don't undersand where/how I send it the variable. I started with something like this. (not working)</p> <pre><code>&lt;?php //Sample XML Object $XML = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt; &lt;data&gt;&lt;foo&gt;1&lt;/foo&gt;&lt;/data&gt;"; $XML = simplexml_load_string($XML); // Extend the class class myExt extends ENTERPRISE { function __construct($xmlData) { parent::__construct(); } public function HTMLBlock() { // Set font $this-&gt;SetFont('helvetica', 'B', 10); $html = ' &lt;P style="font-weight:normal;"&gt; This is a test text cell&lt;br /&gt; Foo is set to '.$XML-&gt;foo.' &lt;/P&gt; '; // Title $this-&gt;htmlToBlock(90, '200', $HTML ); } } $pdf = new myExt('L', 'Letter', 'Landscape', true, 'UTF-8', false); ?&gt; </code></pre> <p>Do I somehow send the myExt() an additional parameter? Magically at the end? I tried it but didn't work. Maybe something like:</p> <pre><code>$pdf = new myExt('L', 'Letter', 'Landscape', true, 'UTF-8', false,$XML); </code></pre> <p>Thanks for any guidance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload