<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Types</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Documentaþia limbajului" HREF="langref.html"><LINK REL="PREVIOUS" TITLE="Comments" HREF="language.basic-syntax.comments.html"><LINK REL="NEXT" TITLE="Booleans" HREF="language.types.boolean.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="chapter" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="language.basic-syntax.comments.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.types.boolean.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="language.types" >Cap. 6. Types</A ></H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Cuprins</B ></DT ><DT ><A HREF="language.types.html#language.types.intro" >Introduction</A ></DT ><DT ><A HREF="language.types.boolean.html" >Booleans</A ></DT ><DT ><A HREF="language.types.integer.html" >Integers</A ></DT ><DT ><A HREF="language.types.float.html" >Floating point numbers</A ></DT ><DT ><A HREF="language.types.string.html" >Strings</A ></DT ><DT ><A HREF="language.types.array.html" >Arrays</A ></DT ><DT ><A HREF="language.types.object.html" >Objects</A ></DT ><DT ><A HREF="language.types.resource.html" >Resource</A ></DT ><DT ><A HREF="language.types.null.html" >NULL</A ></DT ><DT ><A HREF="language.pseudo-types.html" >Pseudo-types used in this documentation</A ></DT ><DT ><A HREF="language.types.type-juggling.html" >Type Juggling</A ></DT ></DL ></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.types.intro" >Introduction</A ></H1 ><P > PHP supports eight primitive types. </P ><P > Four scalar types: <P ></P ><UL ><LI ><P > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A > </P ></LI ><LI ><P > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A > </P ></LI ><LI ><P > <A HREF="language.types.float.html" ><B CLASS="type" >float</B ></A > (floating-point number, aka '<A HREF="language.types.float.html" ><B CLASS="type" >double</B ></A >') </P ></LI ><LI ><P > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A > </P ></LI ></UL > Two compound types: <P ></P ><UL ><LI ><P > <A HREF="language.types.array.html" ><B CLASS="type" >array</B ></A > </P ></LI ><LI ><P > <A HREF="language.types.object.html" ><B CLASS="type" >object</B ></A > </P ></LI ></UL > And finally two special types: <P ></P ><UL ><LI ><P > <A HREF="language.types.resource.html" ><B CLASS="type" >resource</B ></A > </P ></LI ><LI ><P > <A HREF="language.types.null.html" ><B CLASS="type" >NULL</B ></A > </P ></LI ></UL > This manual also introduces some <A HREF="language.pseudo-types.html" >pseudo-types</A > for readability reasons: <P ></P ><UL ><LI ><P > <A HREF="language.pseudo-types.html#language.types.mixed" >mixed</A > </P ></LI ><LI ><P > <A HREF="language.pseudo-types.html#language.types.number" >number</A > </P ></LI ><LI ><P > <A HREF="language.pseudo-types.html#language.types.mixed" >callback</A > </P ></LI ></UL > You may also find some references to the type "double". Consider double the same as float, the two names exist only for historic reasons. </P ><P > The type of a variable is usually not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > If you want to check out the type and value of a certain <A HREF="language.expressions.html" >expression</A >, use <A HREF="function.var-dump.html" ><B CLASS="function" >var_dump()</B ></A >. </P ><P ><B >Notã: </B > If you simply want a human-readable representation of the type for debugging, use <A HREF="function.gettype.html" ><B CLASS="function" >gettype()</B ></A >. To check for a certain type, do <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > use <A HREF="function.gettype.html" ><B CLASS="function" >gettype()</B ></A >, but use the <VAR CLASS="literal" >is_<VAR CLASS="replaceable" >type</VAR ></VAR > functions. Some examples: <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN633" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$bool </font><font color="#007700">= </font><font color="#0000BB">TRUE</font><font color="#007700">; </font><font color="#FF8000">// a boolean<br /></font><font color="#0000BB">$str </font><font color="#007700">= </font><font color="#DD0000">"foo"</font><font color="#007700">; </font><font color="#FF8000">// a string<br /></font><font color="#0000BB">$int </font><font color="#007700">= </font><font color="#0000BB">12</font><font color="#007700">; </font><font color="#FF8000">// an integer<br /><br /></font><font color="#007700">echo </font><font color="#0000BB">gettype</font><font color="#007700">(</font><font color="#0000BB">$bool</font><font color="#007700">); </font><font color="#FF8000">// prints out "boolean"<br /></font><font color="#007700">echo </font><font color="#0000BB">gettype</font><font color="#007700">(</font><font color="#0000BB">$str</font><font color="#007700">); </font><font color="#FF8000">// prints out "string"<br /><br />// If this is an integer, increment it by four<br /></font><font color="#007700">if (</font><font color="#0000BB">is_int</font><font color="#007700">(</font><font color="#0000BB">$int</font><font color="#007700">)) {<br /> </font><font color="#0000BB">$int </font><font color="#007700">+= </font><font color="#0000BB">4</font><font color="#007700">;<br />}<br /><br /></font><font color="#FF8000">// If $bool is a string, print it out<br />// (does not print out anything)<br /></font><font color="#007700">if (</font><font color="#0000BB">is_string</font><font color="#007700">(</font><font color="#0000BB">$bool</font><font color="#007700">)) {<br /> echo </font><font color="#DD0000">"String: $bool"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ></BLOCKQUOTE ></DIV ><P > If you would like to force a variable to be converted to a certain type, you may either <A HREF="language.types.type-juggling.html#language.types.typecasting" >cast</A > the variable or use the <A HREF="function.settype.html" ><B CLASS="function" >settype()</B ></A > function on it. </P ><P > Note that a variable may be evaluated with different values in certain situations, depending on what type it is at the time. For more information, see the section on <A HREF="language.types.type-juggling.html" >Type Juggling</A >. Also, you may be interested in viewing <A HREF="types.comparisons.html" >the type comparison tables</A >, as they show examples of various type related comparisons. </P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="language.basic-syntax.comments.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="language.types.boolean.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Comments</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="langref.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Booleans</TD ></TR ></TABLE ></DIV ></BODY ></HTML >