0

I've seen some code written like this, and I'm really curious what it does and what it's for. Sorry for the unclear title, I appreciate all answers!

Edit: In particular I'm curious about the (string) $variable part

2 Answers 2

1

It's called type casting

Type casting in PHP works much as it does in C: the name of the desired type is written in parentheses before the variable which is to be cast.

<?php
$foo = 10;   // $foo is an integer
$bar = (boolean) $foo;   // $bar is a boolean
?>
The casts allowed are:

(int), (integer) - cast to integer
(bool), (boolean) - cast to boolean
(float), (double), (real) - cast to float
(string) - cast to string
(array) - cast to array
(object) - cast to object
(unset) - cast to NULL (PHP 5)

In your specific example a variable was being cast to a string before being passed as a parameter to testFunction()

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome thanks! I tried searching in google for a long while, but when you don't know exactly what to search, it's difficult to find. I'll accept this as the answer once the wait window is up.
0

It is a function call with an argument. In this case, a variable $variable has been cast to a string for the argument.

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.