9

Magento is throwing a PHP error when I'm trying to create PDF invoices (because my client is running PHP 5.4.19).

Fatal error: Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with Zend_Pdf_FileParserDataSource::__construct() in /var/www/vhosts/website/httpdocs/includes/src/Zend_Pdf_FileParserDataSource_File.php on line 41

Normally it's easy to fix this by editing the FileParserDataSource.php and commenting out two lines, the problem is that they run a Zend_Pdf_FileParserDataSource_File.php that extends this script (http://pastebin.com/J64VNsRP).

Is there any solution available so that's possible to create PDF invoices with Magento on a server running PHP 5.4?

4 Answers 4

36

This an incompatibility issue between PHP Version 5.4.4 and zend Framwork .

Fixed it by change in this function lib/Zend/Pdf/FileParserDataSource.php.

change

abstract public function __construct();

to

abstract public function __construct($filePath);
4
  • Works like a charm! Thanks. Aug 26, 2014 at 8:23
  • Thanks, but this needs to edit core file, which I hate to do. I will certainly report this to Magento core team. Thanks for info. Oct 16, 2015 at 4:14
  • Hey guys, when I open lib/Zend/Pdf/FileParserDataSource.php I don't see abstract public function __construct(); I only have abstract public function __destruct(); and commenting it out doesn't fix an issue. I've also tried to compile as well as disable compilation and that doesn't fix it either. is there alternate method that could fix invoice printing issue?
    – lvekua
    Feb 5, 2016 at 20:27
  • Thank You for a quick solution Jul 11, 2017 at 10:03
6

This is zend core issue http://framework.zend.com/issues/browse/ZF-12093. fix it by commenting out __construct and __destruct methods in lib/Zend/Pdf/FileParserDataSource.php

//    abstract public function __construct();

    /**
     * Object destructor. Closes the data source.
     *
     * May also perform cleanup tasks such as deleting temporary files.
     */
//    abstract public function __destruct();`
9
  • That isn't possible because of the second file.
    – Hidde
    Oct 22, 2013 at 13:00
  • @Hidde, second file means? Oct 22, 2013 at 13:01
  • If I comment out the function __construct(); and function __destruct(); in lib/Zend/Pdf/FileParseDataSource.php there isn't any change because the FileParseDataSource.php gets extended by Zend_Pdf_FileParserDataSource_File.php. If I also comment out the code in that file I get an "contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods" error.
    – Hidde
    Oct 22, 2013 at 13:07
  • @Hidde, have you tried after commenting these function?, because I have fixed same issue for my project. Oct 22, 2013 at 13:14
  • I tried that, yes. It doesn't help, if I comment out the __construct and __destruct in file 1 the error appears in file 2. If I comment out the __construct and __destruct in file 2 the error appears in file 1. If I comment out in both files I get the error mentioned in my previous comment.
    – Hidde
    Oct 22, 2013 at 16:17
2

Sometimes it may be solve by recompile compiler or disable compiler.
Go to System > Tools > Compilation page and click on Run Compilation Process button or Disable button.
Now check print invoice.
http://kb.magenting.com/content/24/81/en/disable-magento-compiler.html

1
  • Run Compilations Process did the job after I run the php 5.4 patch.
    – Timo002
    Feb 9, 2015 at 11:10
1

You will have to change the lib/Zend/Pdf/FileParserDataSource.php and lib/Zend/Pdf/FileParserDataSource/File.php

Find the

             abstract public function __construct();

in FileParserDataSource.php and change it to

             abstract public function __construct($filePath);

And also in the File.php do the same for

             public function __construct()

convert to

             public function __construct($filePath)

This worked for me. I hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.