yoursurrogategod Posted June 18, 2012 Share Posted June 18, 2012 Hello all, this is what I have for a class that I'm working on. <?php include_once "../FTP/FTP.php"; /** * Fax.php: * This is a utility to fax documents using FTP. */ class Lifespan_Fax_Fax extends Zend_View_Helper_Abstract { /** * This is where we will keep the FTP connection object alive. * @var object FTP */ private $ftpConnection; public function __construct($server = '', $port = '', $username = '', $password = '') { if (('' == $server) || ('' == $port) || ('' == $username) || ('' == $password)) { $server = 'ftpofdoom.org'; $port = '10081'; $username = 'cookies'; $password = 'chips'; } $this->ftpConnection = new FTP($server, $port, $username, $password); } public function send($directory, $filename, $data) { $this->ftpConnection->writeToFTPServer($directory, $filename, $data); } } I'm doing this in Zend Studio 9 (our dev environment) and I call new FTP, it says that the FTP class is not found. The class exists in one directory up and in the FTP directory there. Basically this: library/ FTP/ FTP.php Fax/ Fax.php What am I doing wrong? P.S.: No, that is not the legit URL, username or password. You can go there, but I have no idea what you will see . Quote Link to comment https://forums.phpfreaks.com/topic/264391-having-a-hard-time-including-a-php-class/ Share on other sites More sharing options...
cpd Posted June 18, 2012 Share Posted June 18, 2012 The FTP class should be included with a path relative to the file including the Fax file. In other words if you have a file structure as: Library/ MyFoo/ Foo.php MyBar/ Bar.php Test.php Bar.php <?php include '../MyFoo/Foo.php'; ?> Test.php <?php include 'Library/MyBar/Bar.php'; ?> An error will occur because Test.php will go back a directory into LibraryParent/ then try to find a directory called MyFoo/ in there so the overal relative link Test.php searches for via Bar.php is LibraryParent/MyFoo/Foo.php which doesn't exist. That's why your error is cropping up. Quote Link to comment https://forums.phpfreaks.com/topic/264391-having-a-hard-time-including-a-php-class/#findComment-1354884 Share on other sites More sharing options...
KevinM1 Posted June 18, 2012 Share Posted June 18, 2012 Why are you including files manually? Zend Framework should have an autoloader of some kind. Quote Link to comment https://forums.phpfreaks.com/topic/264391-having-a-hard-time-including-a-php-class/#findComment-1354910 Share on other sites More sharing options...
yoursurrogategod Posted June 18, 2012 Author Share Posted June 18, 2012 Why are you including files manually? Zend Framework should have an autoloader of some kind. All I know is that when I mouse over new FTP, I see a little message popping up stating: Class 'FTP' not found Quote Link to comment https://forums.phpfreaks.com/topic/264391-having-a-hard-time-including-a-php-class/#findComment-1354912 Share on other sites More sharing options...
KevinM1 Posted June 18, 2012 Share Posted June 18, 2012 Ah, my mistake. I thought you said Zend Framework, not Zend Studio. That said, PHP has built-in autoload capabilities. __autoload is the classic variant, while spl_autoload_register is the more modern version. Both work well. When writing OO code, you should never need to write include statements for your classes. Quote Link to comment https://forums.phpfreaks.com/topic/264391-having-a-hard-time-including-a-php-class/#findComment-1354918 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.