rgb192
asked on
file is loaded but another error
listing5.14.php
\util\write.php
namespace util;
to
namespace utilFAKE;
file is loaded but why do I get this error:
Fatal error: spl_autoload(): Class util\Writer could not be loaded in C:\wamp\www\POPP-edition4- code\97814 30260318_C hapter_05_ Code\listi ng5.14.php on line 4
<?php
spl_autoload_register();
$writer = new util\Writer();
?>
\util\write.php
<?php
namespace utilFAKE;
class Writer {
}
?>
when I change namespace util;
to
namespace utilFAKE;
file is loaded but why do I get this error:
Fatal error: spl_autoload(): Class util\Writer could not be loaded in C:\wamp\www\POPP-edition4-
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I do not understand julianH example of patterns of how to call class,namespace
because it is too philosophical.
Maybe I would learn better with a real example
please call file
\util\writer.php
because this code will call namespace util, but not namespace utilFAKE
what change needs to be made to call namespace utilFAKE
because it is too philosophical.
Maybe I would learn better with a real example
please call file
\util\writer.php
<?php
namespace utilFAKE;
class Writer {
}
?>
because this code will call namespace util, but not namespace utilFAKE
<?php
spl_autoload_register();
$writer = new util\Writer();
?>
what change needs to be made to call namespace utilFAKE
Just an untested guess, but maybe worth trying this?
<?php
spl_autoload_register();
$writer = new utilFAKE\Writer();
Sidebar note: ALWAYS OMIT THE END-PHP TAG unless it is absolutely necessary. Antipractice # 14
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
<?php
spl_autoload_register();
$writer = new utilFAKE\Writer();
Fatal error: spl_autoload(): Class utilFAKE\Writer could not be loaded in C:\wamp\www\POPP-edition4- code\97814 30260318_C hapter_05_ Code\listi ng5.14.php on line 4
spl_autoload_register();
$writer = new utilFAKE\Writer();
Fatal error: spl_autoload(): Class utilFAKE\Writer could not be loaded in C:\wamp\www\POPP-edition4-
Then your folder structure must be like soso the namespace and foldername must always be same?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
many of these comments brought more understanding about namespace/class/folder
thanks.
thanks.
You are welcome - thanks for the points.
ASKER
everything works until I change the namespace name
I do not know why spl_autoload_register has no arguments
I am copying 2 files from a tutorial. I do not know.
$writer = new util\Writer();
is the 'util' a namespace
and 'writer()' a class
and how does php know to search all the files in the folder to find
/util/writer.php
I wrote /util/write.php which was incorrect.