Should I typecast in PHP when defining my vars?
I am sorry if this is more of a theory question then a real life problem but it is a开发者_StackOverflow社区 real life situation for me. We were commenting on the way PHP works with vars and how memory heavy it is on the server due to its "mixed vars" and something occured to me - why not typecast right from the start?
So I guess my quesion is: Whould it make any difference for the server load if all you PHP vars were"pre-casted"?
Example:
protected $_id;
VS protected (int) $_id;
The question doesn't make any sense as your proposed idea won't even compile in PHP 5. Writing a type within parentheses converts the type to the type in the parentheses. Even if it did compile it wouldn't do anything in variable declarations.
How do you know it is memory heavy due to dynamic typing? Sure there is overhead but there are lots of other things that could cause the memory usage and not all of them bad. For example in a lot of cases virtual machines will grab a lot more memory than required from the heap to speed up memory allocation. The same could be true of the PHP process.
精彩评论