3

Hi when trying to cast from a string to int using int() I get the following error:

Call to undefined function int()

Why would this be?

intval() works just fine but I cannot use int() for some reason.

1
  • 2
    there is no such function in PHP? Commented Aug 13, 2010 at 8:35

3 Answers 3

10

There is no int function; you must use proper typecasting syntax for this:

$b = (int) $a;

Or:

settype($a, 'int');
2
function int($string) {
   return (int) $string;
}
0

Have you tried

$intVar = (int)$var;

If PHP is telling you that int() isn't a function, then it probably isn't.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.