<?php
namespace namespacename;
class classname
{
function __construct()
{
echo __METHOD__,"\n";
}
}
function funcname()
{
echo __FUNCTION__,"\n";
}
const constname = "namespaced";
include 'example1.php';
$a = 'classname';
$obj = new $a; // prints classname::__construct
$b = 'funcname';
$b(); // prints funcname
echo constant('constname'), "\n"; // prints global
/* note that if using double quotes, "\\namespacename\\classname" must be used */
$a = '\namespacename\classname';
$obj = new $a; // prints namespacename\classname::__construct
$a = 'namespacename\classname';
$obj = new $a; // also prints namespacename\classname::__construct
$b = 'namespacename\funcname';
$b(); // prints namespacename\funcname
$b = '\namespacename\funcname';
$b(); // also prints namespacename\funcname
echo constant('\namespacename\constname'), "\n"; // prints namespaced
echo constant('namespacename\constname'), "\n"; // also prints namespaced
?>
Warning: include(): open_basedir restriction in effect. File(example1.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/l3k6F on line 16
Warning: include(example1.php): Failed to open stream: Operation not permitted in /in/l3k6F on line 16
Warning: include(): Failed opening 'example1.php' for inclusion (include_path='.:') in /in/l3k6F on line 16
Fatal error: Uncaught Error: Class "classname" not found in /in/l3k6F:19
Stack trace:
#0 {main}
thrown in /in/l3k6F on line 19
Process exited with code 255.
Output for 8.0.13
Warning: include(example1.php): Failed to open stream: No such file or directory in /in/l3k6F on line 16
Warning: include(): Failed opening 'example1.php' for inclusion (include_path='.:') in /in/l3k6F on line 16
Fatal error: Uncaught Error: Class "classname" not found in /in/l3k6F:19
Stack trace:
#0 {main}
thrown in /in/l3k6F on line 19
Process exited with code 255.
Warning: include(example1.php): failed to open stream: No such file or directory in /in/l3k6F on line 16
Warning: include(): Failed opening 'example1.php' for inclusion (include_path='.:') in /in/l3k6F on line 16
Fatal error: Uncaught Error: Class 'classname' not found in /in/l3k6F:19
Stack trace:
#0 {main}
thrown in /in/l3k6F on line 19
Process exited with code 255.
Warning: include(): open_basedir restriction in effect. File(example1.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/l3k6F on line 16
Warning: include(example1.php): failed to open stream: Operation not permitted in /in/l3k6F on line 16
Warning: include(): Failed opening 'example1.php' for inclusion (include_path='.:') in /in/l3k6F on line 16
Fatal error: Uncaught Error: Class 'classname' not found in /in/l3k6F:19
Stack trace:
#0 {main}
thrown in /in/l3k6F on line 19
Process exited with code 255.
Output for 7.1.20, 7.2.6
Warning: include(): open_basedir restriction in effect. File(example1.php) is not within the allowed path(s): (/tmp:/in) in /in/l3k6F on line 16
Warning: include(example1.php): failed to open stream: Operation not permitted in /in/l3k6F on line 16
Warning: include(): Failed opening 'example1.php' for inclusion (include_path='.:') in /in/l3k6F on line 16
Fatal error: Uncaught Error: Class 'classname' not found in /in/l3k6F:19
Stack trace:
#0 {main}
thrown in /in/l3k6F on line 19
Process exited with code 255.
Warning: include(example1.php): failed to open stream: No such file or directory in /in/l3k6F on line 16
Warning: include(): Failed opening 'example1.php' for inclusion (include_path='.:') in /in/l3k6F on line 16
Fatal error: Class 'classname' not found in /in/l3k6F on line 19
Process exited with code 255.