php Class not found but imported -


i have 2 files, first test.php looks this:

<?php namespace my\namespaces\test;  class test {     const alert_email = "alertemail";     const alert_sms = "alertsms";     const alert_notification = "alertnotification"; }  // class - enumalerttype ?> 

and file try use const test.php

<?php use my\namespaces\test; $a = test::alert_sms; ?> 

but still class 'my\namespaces\test' not found error, i'm not sure if i'm using namespace correctly. thanks

you need differenciate 2 terms here: including , importing. former add code in current script being executed , latter use them in code. including litteraly copy paste code current script can used later on.

thus, need include (require_once()) code of class test file use code. can, indeed, import (use) afterwards (especially if files in separated folders). therefore, need do:

<?php require_once('test.php'); // include code use my\namespaces\test; // import if want not useful 2 file in same folder $a = test::alert_sms; // access class constants 

you should start digging spl_autoloader_register() function.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -