RE: [PHP] Fatal error when calling nested function

From: Date: Fri, 26 Oct 2007 09:46:57 +0000
Subject: RE: [PHP] Fatal error when calling nested function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-263695@lists.php.net to get a copy of this message
> > <?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

« previous php.general (#263695) next »