PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Booleans> <Kommentare
Last updated: Fri, 10 Oct 2008

view this page in

Typen

Inhaltsverzeichnis

Einführung

PHP unterstützt acht primitive Typen.

Vier skalare Typen:

Zwei zusammengesetzte Typen:

Und zuletzt zwei spezielle Typen:

Für die bessere Lesbarkeit führt dieses Handbuch ein paar Pseudo-Typen ein:

Sowie die Pseudovariable $... .

Sie werden auch ein paar Hinweise auf den Typ "Double" finden. Betrachten Sie Double als dasselbe wie Float. Die beiden Bezeichnungen existieren nur aus historischen Gründen.

Der Typ einer Variablen wird normalerweise nicht vom Programmierer bestimmt. Zur Laufzeit von PHP wird entschieden, welchen Typs eine Variable ist, abhängig vom Zusammenhang in dem die Variable benutzt wird.

Hinweis: Um den Typ und den Wert eines bestimmten Ausdrucks (Expression) zu überprüfen, können Sie var_dump() benutzen. Wenn Sie zur Fehlersuche einfach nur eine lesbare Darstellung eines Typs benötigen, benutzen Sie gettype(). Um auf einen bestimmten Typ zu prüfen, sollten Sie nicht gettype() benutzen. Stattdessen sollten Sie die is_type Funktionen verwenden. Ein paar Beispiele:

<?php
$bool 
TRUE;   // ein Boolean (Wahrheitswert)
$str  "foo";  // ein String (Zeichenkette)
$int  12;     // ein Integer (Ganzzahl)

echo gettype($bool); // gibt "boolean" aus
echo gettype($str);  // gibt "string" aus

// Falls es ein Integer ist, erhöhe ihn um vier
if (is_int($int)) {
    
$int += 4;
}

// Falls $bool ein String ist, gebe ihn aus
// (gibt überhaupt nichts aus)
if (is_string($bool)) {
    echo 
"String: $bool";
}
?>

Wenn sie die Umwandlung in einen bestimmten Variablen-Typ erzwingen wollen, erreichen Sie dies entweder durch Typ-Umwandlung oder durch Gebrauch der Funktion settype().

Beachten Sie, dass eine Variable abhängig vom Typ, dem die Variable zu dem Zeitpunkt entspricht, in bestimmten Situationen unterschiedlich ausgewertet werden kann. Weitere Informationen entnehmen Sie dem Abschnitt zur Typ-Veränderung. Schauen Sie sich außerdem PHP type comparison tables an, wenn Sie an Beispielen verschiedener typenbezogener Vergleiche interessiert sind.



Booleans> <Kommentare
Last updated: Fri, 10 Oct 2008
 
add a note add a note User Contributed Notes
Typen
jonah_whalehosting_ca
12-Apr-2007 07:33
In reply to Philip, form data could also be an array.  so there are two types you can expect from $_REQUEST (and it's associates): string and array.
arjini at gmail dot com
06-Dec-2005 09:32
Note that you can chain type castng:

var_dump((string)(int)false); //string(1) "0"
shahnaz khan
18-Mar-2005 01:40
if we use gettype() before initializinf any variable it give NULL
for eg.

<?php
$foo
;
echo
gettype($foo);
?>

it will show

NULL
Trizor of www.freedom-uplink.org
30-Jun-2004 03:14
The differance of float and double dates back to a FORTRAN standard. In FORTRAN Variables aren't as loosly written as in PHP and you had to define variable types(OH NOES!). FLOAT or REAL*4 (For all you VAX people out there) defined the variable as a standard precision floating point, with 4 bytes of memory allocated to it. DOUBLE PRECISION or REAL*8 (Again for the VAX) was identical to FLOAT or REAL*4, but with an 8 byte allocation of memory instead of a 4 byte allocation.

In fact most modern variable types date back to FORTRAN, except a string was called a CHARACHTER*N and you had to specify the length, or CHARACHTER*(*) for a variable length string. Boolean was LOGICAL, and there weren't yet objects, and there was support for complex numbers(a+bi).

Of course, most people reading this are web programmers and could care less about the mathematical background of programming.

NOTE: Object support was added to FORTRAN in the FORTRAN90 spec, and expanded with the FORTRAN94 spec, but by then C was the powerful force on the block, and most people who still use FORTRAN use the FORTRAN77.

Booleans> <Kommentare
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites