Forum Moderators: coopster

Message Too Old, No Replies

echoing variables in an include()

         

noyearzero

1:43 pm on Jan 18, 2008 (gmt 0)

10+ Year Member



here is a script that is giving me fits. I think i'm running php 4.3 or somewhere around there.

why can't i echo variables set with expressions in an include. and just recently it seems like its randomly choosing which variables work and which don't even if they aren't set with expressions.

<?php

$mm = 3440;
$inch = $mm / 25.4;
$inchint = settype($inch,"int");

include('output.php');

echo $mm; // outputs 3440
echo $inch; // outputs 135.43..etc
echo $inchint; // outputs 135.43..etc

?>

output.php
<?php

echo $mm; // outputs 3440
echo $inch; // outputs NULL
echo $inchint; // outputs 0

?>

maxximus

3:21 pm on Jan 18, 2008 (gmt 0)

10+ Year Member



Can't see a problem - you should be echoing
3440 135 and 1.

$inchint should return a boolean only on success or failure.

What do you get with this script

<?php
ini_set("display_errors", "on");
ini_set('error_reporting', E_ALL);
$mm = 3440;
$inch = $mm / 25.4;
$inchint = settype($inch,"int");

include('output.php');

echo "<pre>";var_dump($GLOBALS);
?>

eelixduppy

7:31 pm on Jan 18, 2008 (gmt 0)



Well one reason I can think of depending on your php version is the "int" or "integer" type for the settype function. Try the following for that line:

$inchint = [url=http://www.php.net/set-type]settype[/url]($inch,"integer");

As for the other variable, it should be working as you have intended it to. Try what was suggested above and see what you get as a result.

Also, welcome to WebmasterWorld! :)

noyearzero

7:59 pm on Jan 18, 2008 (gmt 0)

10+ Year Member



i figured out what the problem was. basically i'm an idiot and made some assumptions but they just turned out to be amazing coincidences.

somehow your post jogged my brain, so thanks!

eelixduppy

8:02 pm on Jan 18, 2008 (gmt 0)



hehe, glad you figured out your problem. I'm just curious, though. What was the issue?