note 22636 deleted from function.pow by sniper

From: Date: Fri, 03 Oct 2003 23:26:37 +0000
Subject: note 22636 deleted from function.pow by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57787@lists.php.net to get a copy of this message
Note Submitter: chill@mail.cuna.org ---- 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.

« previous php.notes (#57787) next »