2

I have a class with namespace which require many other classes further . main class is

<?php
/**
 * Deals with PDF document level aspects.
 */
namespace Aspose\Cloud\Pdf;

use Aspose\Cloud\Common\AsposeApp;
use Aspose\Cloud\Common\Product;
use Aspose\Cloud\Common\Utils;
use Aspose\Cloud\Event\SplitPageEvent;
use Aspose\Cloud\Exception\AsposeCloudException as Exception;
use Aspose\Cloud\Storage\Folder;

class Document
{

    public $fileName = '';

    public function __construct($fileName='')
    {
        $this->fileName = $fileName;
    }

    /**
     * Gets the page count of the specified PDF document.
     *
     * @return integer
     */
     public function getFormFields()
    {
        //build URI
        $strURI = Product::$baseProductUri . '/pdf/' . $this->getFileName() . '/fields';

        //sign URI
        $signedURI = Utils::sign($strURI);

        //get response stream
        $responseStream = Utils::ProcessCommand($signedURI, 'GET', '');

        $json = json_decode($responseStream);

        return $json->Fields->List;
    }
}

I am using this like this in index.php

<?
ini_set('display_errors', '1');
use Aspose\Cloud\Pdf;

$document=new Document;
echo $document->GetFormFields();

//or like this 
echo Document::GetFormFields();

//also tried this 
echo pdf::GetFormFields();

?>

Error

Fatal error: Class 'Document' not found in /var/www/pdfparser/asposetry/index.php on line 5

Document class path is Aspose/Cloud/Pdf/Document.php

attempt one

working if i use to include in index.php include(Aspose/Cloud/Pdf/Document.php) but then further namespace produce error. Very difficult to change every use namespace with include. can anybudy tell me the solution for this ??

thanks.

2 Answers 2

2
namespace Aspose\Cloud\Pdf;

class Document {
    ...

To use this class, you'll have to write

use Aspose\Cloud\Pdf\Document

You can also access it without a use statement, but then you'll have to write the full name every time:

$document=new Aspose\Cloud\Pdf\Document;

// Or if you're in a namespace, you'll have to do this:

$document=new \Aspose\Cloud\Pdf\Document;
Sign up to request clarification or add additional context in comments.

2 Comments

Fatal error: Class 'Aspose\Cloud\Pdf\Document' not found in /var/www/pdfparser/asposetry/index.php on line 5 is the error
@ris You'll either have to include each class file, or define an autoloader to do it for you. Take a look here: php.net/manual/en/language.oop5.autoload.php
1

You are trying to use the Document class that's inside the Aspose\Cloud\Pdf namespace, but you are actually using a Document class without a namespace. You have to use one of the following ways:

//Option one:
use Aspose\Cloud\Pdf\Document;
Document::getFormFields();

//Option two:
Aspose\Cloud\Pdf\Document::getFormFields();

Also note that you can't use Document::getFormFields() as a static function, because it is not static. You should make it static (by putting static between public and function) or use it on an object.

7 Comments

Fatal error: Class 'Aspose\Cloud\Pdf\Document' not found in /var/www/pdfparser/asposetry/index.php on line 5 error
You probably forgot to actually include the file with the Document class somewhere in your application. Use autoload or inlcude the file manually: include('Aspose/Cloud/Pdf/Document.php');
now error move to next class. i have to include classess in every class??? this is the error now Fatal error: Class 'Aspose\Cloud\Pdf\Product' not found in /var/www/pdfparser/asposetry/Aspose/Cloud/Pdf/Document.php on line 365
maybe you should consider some autoloader for loading your classes automatically? Standard PHp php.net/manual/de/language.oop5.autoload.php
Yes, you'll either have to include each class seperately (though only once in your application) or use an autoloader as @AdamM suggests. An autoloader checks whether you've already loaded (included) a class when you're using one. If not, it will include it for you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.