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 9044757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:04:12+00:00 2026-06-16T11:04:12+00:00

Trying to extend the FPDF class in PHP with the following code: class Reports

  • 0

Trying to extend the FPDF class in PHP with the following code:

class Reports extends FPDF{

        var $reporttitle = 'TEST';

        function settitle($titlename){      
            $this->$reporttitle = $titlename;
        }
        function header(){
            $this->SetMargins(.5,.5);   
            $this->Image('../../resources/images/img028.png');
            $this->SetTextColor(3,62,107);
            $this->SetFont('Arial','B',14);
            $this->SetY(.7);
            $this->Cell(0,0,$this->$reporttitle,0,0,'R',false,'');
            $this->SetDrawColor(3,62,107);          
            $this->Line(.5,1.1,10,1.1);
        }
    }

I instantiate the class with the variable $pdf and attempt to call the method:

    $pdf = new Reports('L','in','Letter');  
    $pdf-> settitle('Daily General Ledger');
    $pdf->AddPage();    

I get an internal 500 error….debugging tells me that $reporttitle is an empty property. Can anyone provide me with some insight on how to set variable fields in an extended class? Thanks you.

  • 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-16T11:04:13+00:00Added an answer on June 16, 2026 at 11:04 am

    Don’t use the dollar sign to prefix class properties:

                $this->reporttitle = $titlename;
    

    PHP evaluates your $reporttitle first because you used the dollar sign, so you essentially were doing:

    $this-> = $titlename;
    //     ^ nothing
    

    To deomonstrate, if you first delcared $reporttitle = 'reporttitle', it would work.


    Also it’s worth noting that your variable is not private, it’s public because you used the PHP4 var syntax:

    var $reporttitle = 'TEST';
    

    If you want a private variable then use the PHP5 access keyword. Remember that private variables are not accessible to derived classes so if you have a class that extends Reports then reporttitle won’t be accessible.

    private $reporttitle = 'TEST';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

require('inc/fpdf.php'); require('inc/mem_image.php'); class PDF extends FPDF { // Colored table function FancyTable() { $this->SetFont('Helvetica','B');
I'm trying to extend jQuery with the following: $.fn.extend({ initCore: $.fn.init, init: function (selector,
I am trying to extend the PHP5 MySQLi Library class mysqli_ls extends mysqli The
I'm trying to extend LinkdList in Java through the following class definition: public class
I'm trying to extend localStorage w/ the following... localStorage.prototype.setItem2 = function(key,value) { localStorage.setItem(key,value); }
I'm trying to extend the native geolocation function if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var latitude
I'm trying to extend: Mage_Catalog_Model_Product_Visibility I'm modifying the following in the Visibility.php file: public
So I am trying extend the base Application class and add member variables to
I'm Trying to extend a non-moose class, and when I call an accessor defined
I am trying to extend the mysqli class to make a helper class that

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.