php - using namespace -
i want use minimal features of phpmailer. folder structure:
webroot/ - php/ - mail.php - phpmailer/ - phpmailer.php in mail.php, want use namespace:
<?php use phpmailer\phpmailer; $mail = new phpmailer(true); ... but got error:
fatal error: class 'phpmailer\phpmailer' not found in /home/example/public_html/php/mail.php on line 2
how can resolve this?
create include.php file.
$librarypath = "/webroot/php"; set_include_path(get_include_path() . path_separator . $librarypath); ?>
*where $libarypath path of php folder contains phpmailer folder
in phpmailer.php include
namespace phpmailer; class phpmailer(){ ..... } ?>in mail.php include require can instantiate phpmailer\phpmailer
require ('include.php'); use phpmailer\phpmailer;
you can add more class inside php folder , can define namespaces following #2.
you can call them in new pages including 'include.php' , instantiating class.
Comments
Post a Comment