Reputation: 5166
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.
Upvotes: 2
Views: 886
Reputation: 19212
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;
Upvotes: 2
Reputation: 2814
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.
Upvotes: 1