I have very simple web app. Learning how to use namespaces.
Structure of directories is:
www (root)
class (application directory)
index.php
payment (sub-directory for namespace)
card.php (separate class, namespace)
gameplay (sub-directory for namespace)
card.php (separate class, namespace)
Code is as follows:
index.php
<?php
function my_autoload_function($c)
{
require_once "class/".str_replace("\\","/",$c).".php";
}
spl_autoload_register('my_autoload_function');
$gpcard=new \gameplay\card;
$gpcard->play();
?>
card.php (subfolder payment)
<?php
namespace payment;
class Card
{
public function pay()
{
echo "Plaćanje Visa karticom";
}
}
?>
card.php (subfolder gameplay)
<?php
namespace gameplay;
class Card
{
public function play()
{
echo "Igra Dama crvena";
}
}
?>
Error messages which I get are:
1)
Quote:
Warning: require_once(class/gameplay/card.php): failed to open stream: No such file or directory in C:\wamp64\www\class\index.php on line 4
2)
Quote:
Fatal error: require_once(): Failed opening required 'class/gameplay/card.php' (include_path='.;C:\php\pear') in C:\wamp64\www\class\index.php on line 4
Can somebody help with this?
What I have tried:
I tried different solutions with paths but without success.