title: Can you Force Type Casting in PHP?
body: <p>I have been doing some research online and it appears that the answer to my question is no, but I realize there are times when I might miss something or search for something incorrectly. I know in languages like C++, when a variable is declared it can be declared as int or string. Is it possible to force this in PHP?</p>
  
  <p>For Example:</p>
  
  <pre><code>&lt;?php
  (int)$var = 5;
  ?&gt;
  </code></pre>
  
  <p>will be validated and not cause an error in PHP, but:</p>
  
  <pre><code>&lt;?php
  $var = 5;
  ?&gt;
  </code></pre>
  
  <p>will cause an error because it was not cast as a type string, int, object, etc...</p>
  
  <p>I know PHP is loosely typed so this may not be an option, however I would like to use it that way I ensure that I sanitize data appropriately and improve readability by letting others know exactly what is going on with the code. I am hoping there is a way to enforce this in the php.ini file or to load it in a script that will always be executed by my program.</p>
  
  <p>Thank you for any help you can offer! </p>