[Pmwiki-users] Fatal error: call to undefined function: ctype_digit()

Patrick R. Michaud pmichaud
Fri Jun 11 11:11:15 CDT 2004


On Fri, Jun 11, 2004 at 09:46:07AM +1200, John Rankin wrote:
> On Thursday, 10 June 2004 5:13 PM, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> >This is the second time I've seen this bug reported, I think that
> >PHP 4.1.2 doesn't have a ctype_digit() function and that the PHP
> >documentation is incorrect when it says that ctype_digit is
> >available in 4.1.
> 
> I tested with Mac OS X v10.3 (PHP 4.3.2) and it works fine.
> Perhaps is_integer($x) would also work?

Short answer: Alas, probably not, because that tests the type of $x, 
which would be a string in this case.

Medium answer:  I'm just going to change the base code in the next release
to use preg_match and be done with it, since I know that works.

Long explantion of the problem, for those who are interested in such things:  
PHP does something odd with strings beginning with "inf" that is at least 
an annoyance, if not an outright bug.  In the new include syntax  
[[include:PageName#from#to]], PmWiki needs to know out if "from" and "to" 
are numeric, because it locates the text cut points differently in each case.  
Let's say that these anchors are held in the variables $from and $to.

In the first version of PmWiki, I did a simple test for numeric anchors:

   if ($from>0) { ... numeric anchor ... }
   else { ... normal HTML anchor ... }

Normally this works, because PHP will treat strings that don't begin
with digits as having the value zero...

...except if the string begins with "inf" and some additional characters.
In this case PHP thinks the string is equal to the value "infinity",
which is definitely greater than zero.  So, if someone does
[[include:PageName#info_start#info_end]], PHP thinks that "info_start"
and "info_end" have a numeric value of infinity.

Here's an interesting test:
   <?php
      header("Content-type: text/plain");
      $a = "into";
      $b = "info";
      $c = "inf";

      echo "a: $a == ",$a+0,"\n";
      echo "b: $b == ",$b+0,"\n";
      echo "c: $c == ",$c+0,"\n";
   ?>

which outputs

   a: into == 0
   b: info == INF
   c: inf == 0

Note that "info" is treated as infinity, while "inf" by itself is not.

Anyway, this means we can't simply do a test for $x > 0 to see if
$x represents a non-zero numeric value, so we have to check to make
sure that all of the characters are in fact digits by using ctype_digit
or, since that doesn't appear to work in PHP 4.1, preg_match.

I guess I should report this as a bug.

Pm




More information about the pmwiki-users mailing list