note 22636 added to function.pow

From: Date: Tue, 25 Jun 2002 19:02:22 +0000
Subject: note 22636 added to function.pow
Groups: php.notes 
Request: Send a blank email to php-notes+get-32190@lists.php.net to get a copy of this message
The examples given above by the documentation writer all use hard-coded numbers. The POW function can be a bit trickier when used with variables. This is because revisions made to the function after version 4.0.6 move away from the type looseness generally associated with PHP. For example, the following line of code runs under 4.0.6 but raises a warning ("Invalid argument(s) passed to pow()") under 4.2.1: <? php $term2 = 1 / pow(1+$r,$t); ?> The reason? $t has type text. In 4.0.6 this was silently cast to int, but not in 4.2.1. One way to ensure this line of code works: <? php $term2 = 1 / pow(1+$r,intval($t)); ?> Of course the current type of $t could be checked before passing it to POW. However, if PHP is going to go in this direction, it might be easier on programmers to enforce strict typing as in C. -- http://www.php.net/manual/en/function.pow.php http://master.php.net/manage/user-notes.php?action=edit+22636 http://master.php.net/manage/user-notes.php?action=delete+22636 http://master.php.net/manage/user-notes.php?action=reject+22636

« previous php.notes (#32190) next »