RE: Fatal error when calling nested function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>
> <?php
> function salestax($price,$tax) {
> function convert_pound($dollars, $conversion=1.6) {
> return $dollars * $conversion;
> }
> $total = $price + ($price * $tax);
> echo "Total cost in dollars: $total. Cost in British pounds: "
> .convert_pound($total);
> }
> salestax(15.00,.075);
> echo "<br />" . convert_pound(15);
> ?>
>

That's still pretty nasty though:

<?php

<snip>

salestax(15.00,.075);
salestax(15.00,.075);
?>

gives:

Total cost in dollars: 16.125. Cost in British pounds: 25.8
24
Fatal error: Cannot redeclare convert_pound() ...


What's wrong with non-nested functions? i.e.:

function convert_pound($dollars, $conversion=1.6) {
        return $dollars * $conversion;
}

function salestax($price,$tax) {
        $total = $price + ($price * $tax);
        echo "Total cost in dollars: $total. Cost in British pounds: "
        .convert_pound($total);
}

E

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux