Ich habe mal eine Frage, udnzwar habe ich mir angewöhnt alle Typen zuweisungen manuell zu machen, ich habe mal ein beispiel erstellt...
PHP-Code:
<?php
# # # Handling von Typen in PHP 4,5 # # # # # # # # # # # # # # #
# Links: #
# [url]http://www.php.net/manual/de/language.types.type-juggling.php[/url] #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Fehleranzeige an.
error_reporting(E_ALL);
## Ein String wird explizit als String gekennzeichnet und ausgegeben.
echo (string)'Test mit echo';
## Eine variable wird als String formatiert.
$foo = (string)'Ein String wird angelegt';
## Überprüfe den Type
echo (string)'<hr \>';
if(is_string($foo)) { print (string)('$foo ist ein String'); } else { print (string)('$foo ist kein String'); }
## umwandeln eines Types
settype($foo, "integer");
## Überprüfe den Type
echo (string)'<hr \>';
if(is_string($foo)) { print (string)('$foo ist ein String'); } else { print (string)('$foo ist kein String und hat den Wert '.$foo); }
## Array und verschiedene String Typen
$foo = array();
$foo['string'] = (string)'ein String';
$foo['int'] = (int)15;
$foo['bool'] = (bool)143;
## Alles ausgeben
echo (string)'<hr \>';
foreach((array)$foo as $key => $value)
{
print (string)(' $foo['.$key.'] ist vom Typ: '.gettype($foo[$key]).'<br \>');
}
## Echtzeit änderung
$foo = (string)'tim';
## Ausgeben
echo (string)'<hr \>';
print('$foo ist '.gettype($foo).'<br \>');
print('$foo formatiert zu '.gettype((object)$foo).'<br \>');
print('$foo formatiert zu '.gettype((int)$foo).'<br \>');
print('$foo formatiert zu '.gettype((array)$foo).'<br \>');
print('$foo war '.gettype($foo).'<br \>');
## Type-Handling innerhalb eines Strings
echo (string)'<hr \>';
$foo = (int)1234 .(string)'test';
print('$foo ist '.gettype($foo).'<br \>');
?>
ein wenig überzogen ist dies natürlich, nun meine frage:
schadet dies der performence oder wird diese dadurch beschleunigt da php die arbeit abgenommen wird ... ?