<HTML ><HEAD ><TITLE >Functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Language Reference" HREF="langref.html"><LINK REL="PREVIOUS" TITLE="include" HREF="function.include.html"><LINK REL="NEXT" TITLE="Function arguments" HREF="functions.arguments.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><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="function.include.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="functions.arguments.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="functions" >Chapter 12. Functions</A ></H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="functions.html#functions.user-defined" >User-defined functions</A ></DT ><DT ><A HREF="functions.arguments.html" >Function arguments</A ></DT ><DT ><A HREF="functions.returning-values.html" >Returning values</A ></DT ><DT ><A HREF="functions.old-syntax.html" ><TT CLASS="literal" >old_function</TT ></A ></DT ><DT ><A HREF="functions.variable-functions.html" >Variable functions</A ></DT ></DL ></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="functions.user-defined" >User-defined functions</A ></H1 ><P > A function may be defined using syntax such as the following: <DIV CLASS="informalexample" ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 function foo ($arg_1, $arg_2, ..., $arg_n) { 3 echo "Example function.\n"; 4 return $retval; 5 } 6 </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > Any valid PHP code may appear inside a function, even other functions and <A HREF="oop.html#keyword.class" >class</A > definitions. </P ><P > In PHP3, functions must be defined before they are referenced. No such requirement exists in PHP4. </P ><P > PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions. </P ><P > PHP3 does not support variable numbers of arguments to functions, although default arguments are supported (see <A HREF="functions.arguments.html#functions.arguments.default" >Default argument values</A > for more information). PHP4 supports both: see <A HREF="functions.arguments.html#functions.variable-arg-list" >Variable-length argument lists</A > and the function references for <A HREF="function.func-num-args.html" ><B CLASS="function" >func_num_args()</B ></A >, <A HREF="function.func-get-arg.html" ><B CLASS="function" >func_get_arg()</B ></A >, and <A HREF="function.func-get-args.html" ><B CLASS="function" >func_get_args()</B ></A > for more information. </P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.include.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="functions.arguments.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.include.html" ><B CLASS="function" >include()</B ></A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="langref.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Function arguments</TD ></TR ></TABLE ></DIV ></BODY ></HTML >