Can't import defined variables?

2 replies
I'm trying to learn PHP by following the PHP manual, but one of the examples doesn't seem to work for me when I tried it. What I am doing is attempting to import a defined variable to another PHP file and then doing a simple echo of the variable name and value like such:

Code:
variables.php:
define("MY_VERSION", 1.1);

printoff.php:
obstart();
include './variables.php';
ob_end_clean();
echo "MY_VERSION"; //should print MY_VERSION
echo "My_version"; //should print 1.1
What am I doing wrong here?

Should note the error I get is "Use of undefined constant"
#defined #import #variables
  • Profile picture of the author IronMike
    To make it work as it should change the printoff.php file to this:
    PHP Code:
    <?php

    ob_start
    ();
    include 
    './variables.php';
    ob_end_clean();
    echo 
    "MY_VERSION"//should print MY_VERSION
    echo MY_VERSION//should print 1.1

    ?>
    obstart was changed to ob_start and the quotes were taken out from around the last MY_VERSION and it was put in the proper case.
    {{ DiscussionBoard.errors[6560522].message }}
    • Profile picture of the author Brandon Tanner
      If variables.php is in the same folder as printoff.php, then the include line should be...

      include 'variables.php';

      instead of...

      include './variables.php';

      Or if variables.php is in one folder up from printoff.php, then the include line should be...

      include '../variables.php';
      Signature

      {{ DiscussionBoard.errors[6560617].message }}

Trending Topics