By jockox3@drupal.org on
I'm not a PHP expert, but I am able with difficulty to read the code and follow others' logic and sometimes spot where a problem might be fixed, and I'm currently trying to do something like that with the registerprofile.module.
There's a line in it that I don't understand what it's doing - what the syntax means in PHP and I've referred to my PHP books and can't find anything in there that explains what this construct is doing:
$var1 = (object)$var2;
Anyone able to enlighten me?
Cheers,
Jock
Comments
Type casting
Hi Jock
This line is an explicit type conversion, or type cast. It's ensuring that $var1 has the type "object" when it is assigned the value of $var2.
It's more commonly used to convert between different (but similar) types, such as converting a float to an int (albeit with some loss of data).
Wikipedia has a page on this topic; check out the explicit type conversion section.
HTH
Alastair
Thanks...
...I did also just find reference to it myself at:
http://www.php.net/manual/en/language.oop5.php#op5.intro
..and was about to conclude the same thing. But thanks for confirming!
Jock