ZF-2702: Fatal error: Class 'Zend_Pdf_Resource_Image' not found

Description

Get fatal error:

Fatal error: Class 'Zend_Pdf_Resource_Image' not found in [...cut...]/Zend/Pdf/Resource/Image/Jpeg.php on line 41

Which I would suspect is a loading error but everything is fine otherwise. The strangest part is that I can reproduce the error simply by doing:

new Zend_Pdf_Resource_Image();

Then I get that Jpeg error. Very strange. The class seems to load but then disappear?

The error originally occurred while trying to create a code coverage report using PHPUnit.

Comments

After much testing I've determined this is the result of the require_once structure in the various files. It seems that if you don't require the object in the correct order it creates a "loop" where the require structure dies and the object is never really instantiated. The error actually occurs when you simply require the file! If you haven't loaded any other PDF stuff, just do this:

require 'Zend/Pdf/Resource/Image.php';

and you'll get the error. This happens because the require line do this:

Zend/Pdf/Resource/Image.php requires -> Zend/Pdf/Element/Object.php requires -> Zend/Pdf/ElementFactory.php requires -> Zend/Pdf/Element/Reference.php requires -> /Zend/Pdf/Element/Reference/Context.php requires -> Zend/Pdf/StringParser.php requires -> Zend/Pdf/Element/Object/Stream.php requires -> Zend/Pdf/Element/Stream.php requires -> Zend/Pdf.php requires -> Zend/Pdf/Resource/Image/Jpeg.php requires -> Zend/Pdf/Resource/Image.php

LOOP!!!

The last require doesn't actually happen since it already occurred (once) above but that means PHP then tries to parse Zend_Pdf_Resource_Image_Jpeg BEFORE Zend_Pdf_Resource_Image has been parsed.

The same applies to Tiff and such if you start requiring different files.

Please evaluate and categorize as necessary.

Zend_Pdf component objects are not intended to be used one by one.

In some places it's only "declaration", that this class needs som other(s). And it sometimes makes loops.

Actual require_once (and file parcing) order is defined by require_once tree (graph) starting from Zend_Pdf.

So you should always use:


<?php
require_once 'Zend/Pdf.php';
...

to work with Zend_Pdf component.

Updating for the 1.6.0 release.