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');
Sign up to request clarification or add additional context in comments.

Comments

2
function int($string) {
   return (int) $string;
}

Comments

0

Have you tried

$intVar = (int)$var;

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.