views:

174

answers:

3

I am sorry if this is more of a theory question then a real life problem but it is a 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;

A: 

refer the following link

http://php.net/manual/en/language.types.type-juggling.php

muruga
I have before but thank you.
Borislav
+5  A: 

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.

Yacoby
Well to be honest I have not done any observation on our servers and I only commented on PHP's "hunger" due to its preceding reputation of a resource hog (when compared to for example ASP or lower level languages such as C). I apologize if what I wrote sounded foolish but I was only trying to figure out if my code can be better optimized. Thanks for the answer.
Borislav
A: 

It will be good if we are type casting user submitted data, or data value seems too flexible helps to improve security. else if generated data is in our control then we can skip it

ricky