Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:12:34+00:00 2026-06-01T04:12:34+00:00

The concept of adding a variable to a class’s extension is something I am

  • 0

The concept of adding a variable to a class’s extension is something I am not grasping and could use some help.

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.

<?php

//Sample XML Object
  $XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
        <data><foo>Bingo!</foo></data>";
  $XML = simplexml_load_string($XML);
// Extend the class
  class myExt extends ENTERPRISE {
      public function HTMLBlock() {
          // Set font
          $this->SetFont('helvetica', 'B', 10);
          $html = '
            <P style="font-weight:normal;">
             This is a test text cell<br />
             Foo is set to '.$XML->foo.'
            </P>
          ';
          // Title
          $this->htmlToBlock(90, '200', $HTML );
       }
  }

  $pdf = new myExt('L', 'Letter', 'Landscape', true, 'UTF-8', false);
?>  

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)

<?php

//Sample XML Object
  $XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
        <data><foo>1</foo></data>";
  $XML = simplexml_load_string($XML);

// Extend the class
  class myExt extends ENTERPRISE {
      function __construct($xmlData) {
        parent::__construct();
      }
      public function HTMLBlock() {
          // Set font
          $this->SetFont('helvetica', 'B', 10);
          $html = '
            <P style="font-weight:normal;">
             This is a test text cell<br />
             Foo is set to '.$XML->foo.'
            </P>
          ';
          // Title
          $this->htmlToBlock(90, '200', $HTML );
       }
  }

  $pdf = new myExt('L', 'Letter', 'Landscape', true, 'UTF-8', false);
?>  

Do I somehow send the myExt() an additional parameter? Magically at the end? I tried it but didn’t work. Maybe something like:

$pdf = new myExt('L', 'Letter', 'Landscape', true, 'UTF-8', false,$XML);

Thanks for any guidance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:12:37+00:00Added an answer on June 1, 2026 at 4:12 am

    This is a really simple example, but if the constructor takes 6 arguments and you wanted to pass it an additional argument you could just override the default constructor. If you post the ENTERPRISE class I’ll update this response!

    <?php
    
    //Sample XML Object
      $XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
            <data><foo>Bingo!</foo></data>";
      $XML = simplexml_load_string($XML);
    // Extend the class
      class myExt extends ENTERPRISE {
          var $XML;
          function __construct($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $XML)
          {
            parent::__construct($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
            $this->XML = $XML;
          }
          public function HTMLBlock() {
              // Set font
              $this->SetFont('helvetica', 'B', 10);
              $html = '
                <P style="font-weight:normal;">
                 This is a test text cell<br />
                 Foo is set to '.$this->XML->foo.'
                </P>
              ';
              // Title
              $this->htmlToBlock(90, '200', $HTML );
           }
      }
    
      $pdf = new myExt('L', 'Letter', 'Landscape', true, 'UTF-8', false, $XML);
    ?> 
    

    Also note that variables in PHP ARE case-sensitive. So in your HTMLBlock method $html != $HTML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to use this concept in one of my upcoming project. More
This concept is a new one for me -- I first came across it
This concept is new to me, and a colleague suggested it. Sadly, I had
One concept I've always wondered about is the use of cryptographic hash functions and
This concept seems to trouble me. Why does an NSError object need its pointer
I 'm trying to grasp the concept of versioning css/js files. www.prelovac.com/vladimir/adding-version-to-theme-css-file <link rel=stylesheet
First off, please forgive the stupidness of this question but Im not from a
I'm having some issues wrapping my head around the concept of classloading, I've been
First, I'd like to apologize for adding to the myriad of questions on this
Learning javascript when I came across the concept of prototype. I succeeded in adding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.