File 1 - /Users/jitendraojha/www/DesignPatternsWithPhpLanguage/FactoryPattern/FactoryClassPattern/UserInterface.php
<?php
namespace DesignPatternsWithPhpLanguage\FactoryPattern\FactoryClassPattern;
interface UserInterface
{
function setFirstName($firstName);
function getFirstName();
}
?>
File 2 - /Users/jitendraojha/www/DesignPatternsWithPhpLanguage/FactoryPattern/FactoryClassPattern/User.php
<?php
namespace DesignPatternsWithPhpLanguage\FactoryPattern\FactoryClassPattern;
class User implements UserInterface
{
private $firstName = null;
public function __construct($params) { }
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
public function getFirstName()
{
return $this->firstName;
}
}
?>
Problem
php FactoryPattern/FactoryClassPattern/UserInterface.php
- Runs fine.
php FactoryPattern/FactoryClassPattern/User.php
- gives following errors: PHP Fatal error: Interface 'DesignPatternsWithPhpLanguage\FactoryPattern\FactoryClassPattern\UserInterface' not found in /Users/jitendraojha/www/DesignPatternsWithPhpLanguage/FactoryPattern/FactoryClassPattern/User.php on line 7
I had use UserInterface;
added in File 2 with no solution.
All you need its include, but better yet you should use an autoloader
See example below for quick test with include, assumption here is both files are in the same directory.
namespace DesignPatternsWithPhpLanguage\FactoryPattern\FactoryClassPattern;
include('UserInterface.php');
class User implements UserInterface
{
private $firstName = null;
public function __construct($params) { }
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
public function getFirstName()
{
return $this->firstName;
}
}
// Quick test will - output ===> John
$user = new User(null);
$user->setFirstName('John');
echo $user->getFirstName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With