<HTML ><HEAD ><TITLE >Resource</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Types" HREF="language.types.html"><LINK REL="PREVIOUS" TITLE="Objects" HREF="language.types.object.html"><LINK REL="NEXT" TITLE="NULL" HREF="language.types.null.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" 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" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="language.types.object.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 7. Types</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.types.null.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.types.resource" ></A >Resource</H1 ><P > A resource is a special variable, holding a reference to an external resource. Resources are created and used by special functions. See the <A HREF="resource.html" >appendix</A > for a listing of all these functions and the corresponding resource types. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The resource type was introduced in PHP 4 </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.types.resource.casting" ></A >Converting to resource</H2 ><P > As resource types hold special handlers to opened files, database connections, image canvas areas and the like, you cannot convert any value to a resource. </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.types.resource.self-destruct" ></A >Freeing resources</H2 ><P > Due to the reference-counting system introduced with PHP4's Zend-engine, it is automatically detected when a resource is no longer referred to (just like Java). When this is the case, all resources that were in use for this resource are made free by the garbage collector. For this reason, it is rarely ever necessary to free the memory manually by using some free_result function. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Persistent database links are special, they are <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > destroyed by the garbage collector. See also the section about <A HREF="features.persistent-connections.html" >persistent connections</A >. </P ></BLOCKQUOTE ></DIV > </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.types.object.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="language.types.null.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Objects</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="language.types.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >NULL</TD ></TR ></TABLE ></DIV ></BODY ></HTML >