Magento PHP 5.4 PDF invoice Zend error
Asked Answered
S

4

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?

Silicify answered 22/10, 2013 at 11:29 Comment(0)
M
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);
Manhattan answered 23/10, 2013 at 9:46 Comment(3)
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.Aiden
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?Danseur
Thank You for a quick solutionVeneration
M
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();`
Mcferren answered 22/10, 2013 at 12:49 Comment(9)
That isn't possible because of the second file.Silicify
@Hidde, second file means?Mcferren
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.Silicify
@Hidde, have you tried after commenting these function?, because I have fixed same issue for my project.Mcferren
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.Silicify
Rajiv's suggestion should work fine. Only comment out the abstract declarations in lib/Zend/Pdf/FileParserDataSource.php. The error you're getting is because the declarations in Zend_Pdf_FileParserDataSource_File don't match the ones in Zend_Pdf_FileParserDataSource. If you're still getting this error after editing the latter, you didn't edit the correct file. (And note that the file paths in your error don't seem to match the file structure of Magento, so something weird's going on.)Spooner
Also, this error was fixed a long time ago in ZF. Magento is using quite an old version of the framework.Spooner
@Tim 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 41Silicify
It's not possible for you to be getting this error after successfully making Rajiv's change. PHP cannot complain about the constructor of /var/www/vhosts/website/httpdocs/includes/src/Zend_Pdf_FileParserDataSource_File‌​.php if you've removed the constructor. Are you 100% sure you've edited the correct file? Perhaps an opt cache is caching the old version (try restarting your web server after making the change).Spooner
M
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

Mccowan answered 23/5, 2014 at 4:5 Comment(1)
Run Compilations Process did the job after I run the php 5.4 patch.Complacent
M
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.

Mertiemerton answered 24/8, 2016 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.