O/S: Ubuntu 9.04 Jaunty Jackalope
PHP version (from phpinfo): PHP Version 5.2.6-3ubuntu4.1
Hi all, I'm a noobie to PHP. I'm going through a book to learn PHP and do not know why this simple example is not working. I've Googled on magic constants and find plenty of examples like the one I already have.
<?
echo "This is file "._FILE_ ;
echo "This is line number "._LINE_ ;
<?>
Output:
This is file _FILE_
This is line number _LINE_
Why isn't the code above working as expected? Is there a configuration setting I need to change for these "magic constants" to work?
TIA!
John
Problem getting results from Magic Constants
Moderator: General Moderators
Problem getting results from Magic Constants
Last edited by JohnE1 on Mon Jun 29, 2009 1:46 pm, edited 1 time in total.
Re: Problem getting results from Magic Constants
http://us2.php.net/manual/en/language.constants.php
look again
__FILE__
PS: String concatenation in PHP is done by using "." operator:
look again
__FILE__
PS: String concatenation in PHP is done by using "." operator:
Code: Select all
echo "Variable A has value of ".$a;
Last edited by pickle on Mon Jun 29, 2009 2:35 pm, edited 1 time in total.
Reason: Fixing "String" spelled as "Sting"
Reason: Fixing "String" spelled as "Sting"
There are 10 types of people in this world, those who understand binary and those who don't
Re: Problem getting results from Magic Constants
Thanks, but that didn't fix it. The original code example in the book had the dots, I just left them out by mistake in my forum message for help.
I have tried using the dots with no space around them and with a blank space on each side of them, and the results are still the same... the code doesn't work as it should.
Is there something else that can prevent the magic constants from working?
I'm thinking there's a configuration setting I need to change. Is there something on phpinfo()'s output you'd like me to check?
John
I have tried using the dots with no space around them and with a blank space on each side of them, and the results are still the same... the code doesn't work as it should.
Is there something else that can prevent the magic constants from working?
I'm thinking there's a configuration setting I need to change. Is there something on phpinfo()'s output you'd like me to check?
John
Re: Problem getting results from Magic Constants
There was more code to the example, so I decided to add it and test it.
To my surprise, the new lines (with constants that begin with "PHP_") worked!
Thanks for any help in solving this mystery.
John
To my surprise, the new lines (with constants that begin with "PHP_") worked!
Code: Select all
<?
echo "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;
?>
This file is _FILE_
This is line number _LINE_
I am using 5.2.6-3ubuntu4.1
This test is being run on Linux John
Re: Problem getting results from Magic Constants
The magic constants are:
[underscore][underscore]FILE[underscore][underscore], not
[underscore]FILE[underscore]
[underscore][underscore]FILE[underscore][underscore], not
[underscore]FILE[underscore]
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Problem getting results from Magic Constants
Thank you, thank you, guys!!
Double underscore.... WOW!!
I went back and looked at the book... and it looks like the book's publisher made the very same mistake, because the underscores around FILE and LINE look the same length as the one after PHP_ , and author never bothered to point out the importance of 2 underscores. I don't feel so blind now, but I can use old age as an excuse. LOL
John
Double underscore.... WOW!!
I went back and looked at the book... and it looks like the book's publisher made the very same mistake, because the underscores around FILE and LINE look the same length as the one after PHP_ , and author never bothered to point out the importance of 2 underscores. I don't feel so blind now, but I can use old age as an excuse. LOL
John