hi, i am using php version 4.1.3 and i was using php constants like _FILE_ and _LINE_ in echo statements but when i run these statements in browser they give error that constants are undefined but other php constants like one for php version and operating system work quite well.. what might be the possible reason for this?

please post your code.

this works for me:

define("_FILE_", "this is a file"); 
define("_LINE_", "this is a line"); 

echo _FILE_;
echo "<br>";
echo _LINE_;
<html>
    <head>
         <title>php constants</title>
    </head>
    <body>
       
       <?php
	
	echo "<br>This file is "._FILE_;
        echo "<br>This is line number "._LINE_;
        echo "<br>I am using ".PHP_VERSION;
        echo "<br>This test is being run on ".PHP_OS;
      
        ?>
    
    </body>

</html>

and errors
Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\constants.php on line 9

This file is _FILE_
Notice: Use of undefined constant _LINE_ - assumed '_LINE_' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\constants.php on line 10

This is line number _LINE_
I am using 4.3.10
This test is being run on WINNT
-------------------------------------------
well but whats the matter with this one?

sorry actually i m new to php so i thought that file and line constants also do not need to be supplied values expilcitly. thanx

I think you mean to use:

__FILE__
and
__LINE__

Notice the 2 underscores.

hi, i am using php version 4.1.3 and i was using php constants like _FILE_ and _LINE_ in echo statements but when i run these statements in browser they give error that constants are undefined but other php constants like one for php version and operating system work quite well.. what might be the possible reason for this?

I just found out it should be __FILE__ and __LINE__ 2 underscores on each side of the magic constant.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.