Magento PHP 5.4 PDF invoice Zend error
Solution 1
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);
Solution 2
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();`
Solution 3
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
Solution 4
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.
Hidde
Updated on July 21, 2022Comments
-
Hidde almost 2 years
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?
-
Hidde over 10 yearsThat isn't possible because of the second file.
-
Rajiv Ranjan over 10 years@Hidde, second file means?
-
Hidde over 10 yearsIf 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.
-
Rajiv Ranjan over 10 years@Hidde, have you tried after commenting these function?, because I have fixed same issue for my project.
-
Hidde over 10 yearsI 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.
-
Tim Fountain over 10 yearsRajiv'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 inZend_Pdf_FileParserDataSource_File
don't match the ones inZend_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.) -
Tim Fountain over 10 yearsAlso, this error was fixed a long time ago in ZF. Magento is using quite an old version of the framework.
-
Hidde over 10 years@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 41
-
Tim Fountain over 10 yearsIt'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). -
Hashid Hameed over 9 yearsWorks like a charm! Thanks.
-
Timo002 about 9 years
Run Compilations Process
did the job after I run the php 5.4 patch. -
Adarsh Khatri over 8 yearsThanks, but this needs to edit core file, which I hate to do. I will certainly report this to Magento core team. Thanks for info.
-
lvekua about 8 yearsHey 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?
-
Wasiq Shahrukh almost 7 yearsThank You for a quick solution