cvs: phpdoc /kr/language variables.xml
| From: | WonHee Hwang | Date: | Tue, 09 Jan 2001 08:23:41 +0000 |
| Subject: | cvs: phpdoc /kr/language variables.xml | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969333499@lists.php.net to get a copy of this message | ||
regina Tue Jan 9 00:23:41 2001 EDT
Added files:
/phpdoc/kr/language variables.xml
Log:
Index: phpdoc/kr/language/variables.xml +++ phpdoc/kr/language/variables.xml <chapter id="language.variables"> <title>ë³ì (Variables)</title> <sect1 id="language.variables.basics"> <title>기본(Basics)</title> <simpara> Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. </simpara> <para> Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' </para> <note> <simpara> For our purposes here, a letter is a-z, A-Z, and the ASCII characters from 127 through 255 (0x7f-0xff). </simpara> </note> <para> <informalexample> <programlisting role="php"> $var = "Bob"; $Var = "Joe"; echo "$var, $Var"; // outputs "Bob, Joe" $4site = 'not yet'; // invalid; starts with a number $_4site = 'not yet'; // valid; starts with an underscore $t㸴e = 'mansikka'; // valid; '⥠is ASCII 228. </programlisting> </informalexample> </para> <para> In PHP 3, variables are always assigned by value. That is to say, when you assign an expression to a variable, the entire value of the original expression is copied into the destination variable. This means, for instance, that after assigning one variable's value to another, changing one of those variables will have no effect on the other. For more information on this kind of assignment, see <link linkend="language.expressions">Expressions</link>. </para> <para> PHP 4 offers another way to assign values to variables: <emphasis>assign by reference</emphasis>. This means that the new variable simply references (in other words, "becomes an alias for" or "points to") the original variable. Changes to the new variable affect the original, and vice versa. This also means that no copying is performed; thus, the assignment happens more quickly. However, any speedup will likely be noticed only in tight loops or when assigning large arrays or objects. </para> <para> To assign by reference, simply prepend an ampersand (&) to the beginning of the variable which is being assigned (the source variable). For instance, the following code snippet outputs 'My name is Bob' twice: <informalexample> <programlisting role="php"> <?php $foo = 'Bob'; // Assign the value 'Bob' to $foo $bar = &$foo; // Reference $foo via $bar. $bar = "My name is $bar"; // Alter $bar... echo $foo; // $foo is altered too. echo $bar; ?> </programlisting> </informalexample> </para> <para> One important thing to note is that only named variables may be assigned by reference. <informalexample> <programlisting role="php"> <?php $foo = 25; $bar = &$foo; // This is a valid assignment. $bar = &(24 * 7); // Invalid; references an unnamed expression. function test() { return 25; } $bar = &test(); // Invalid. ?> </programlisting> </informalexample> </para> </sect1> <sect1 id="language.variables.predefined"> <title>미리 ì ìë ë³ì (Predefined variables)</title> <simpara> PHPë 모ë ì¤í¬ë¦½í¸ì ëí´ ê·¸ ì¤í¬ë¦½í¸ê° ì¤í ë ë ì¬ë¬ê°ì 미리 ì ìë ë³ì를 ì ê³µíë¤. ì´ ë³ìì¤ ìë²ì ì¢ ë¥ë ë²ì , 기í ë¤ë¥¸ ìì¸ì¼ë¡ ì¸í´ ë¬ë¼ì§ë ê²ë ë§ìë°, ê·¸ë° ë³ìë ì´ê³³ì 문ìí ëì§ ììë¤. ëí ì´ ë³ìì¤ ë¤ìë PHPê° command-lineì¼ë¡ ëìí ëë ì¬ì©í ì ìë¤. </simpara> <simpara> ì´ë° ì¬ë¬ ìì¸ì´ ìì§ë§ ì´ê³³ììë ê°ì¥ ì¼ë°ì ì¸ íê²½ì¸ <ulink url="&url.apache;">Apache</ulink> 1.3.6 ìì 모ëë¡ PHP3를 ì¤ì¹í íê²½ììì 미리 ì ìë ë³ì를 ì´í´ë³´ëë¡ íì. </simpara> <simpara> ì¬ë¬ë¶ì´ ì¬ì©íë ìì¤í ì 모ë 미리 ì ìë ë³ì를 ë³´ë ¤ë©´ <function>phpinfo</function> í¨ì를 ì¬ì©íì. (ì´ í¨ìë ë¤ë¥¸ ì¬ë¬ ì ì©í ì ë³´ë ìë ¤ì¤ë¤.) </simpara> <note> <simpara> ì¬ê¸°ëì¨ ëª©ë¡ì ìì íì§ ìë¤. (ìë²½í ìê°ë ìë¤.) ì´ ëª©ë¡ì ë¨ìí ì¬ë¬ë¶ì ì¤í¬ë¦½í¸ìì ì´ë¤ ì¢ ë¥ì 미리 ì ìë ë³ìê° ì¬ì©ë ì ìëê°ì ììì¼ ë¿ì´ë¤. </simpara> </note> <sect2 id="language.variables.predefined.apache"> <title>Apache variables</title> <simpara> ì´ ë³ìë <ulink url="&url.apache;">Apache</ulink> ì¹ìë²ë¡ë¶í° ìì±ë ê²ì´ë¤. ë§ì½ ì¬ë¬ë¶ì´ ë¤ë¥¸ ì¹ìë²ë¥¼ ì¬ì©íê³ ìë¤ë©´ ì´ì ëì¼í ë³ìê° ìì±ëë¤ê³ ë³´ì¥í ì ìë¤. ìë§ë ì¼ë¶ë ìì´ì§ê³ , ì¬ê¸°ì ìë ë³ìê° ìë¡ ì길 ê²ì´ë¤. ì¬ê¸°ì ìë ë³ìì¤ ëë¶ë¶ì <ulink url="&url.cgispec;">CGI 1.1 specification</ulink>ìì ëì¨ ê²ì´ê³ , ê·¸ ë´ì©ëë¡ ì¬ì©ëë¤. </simpara> <simpara> ì´ê³³ì ìë ë³ìì¤ PHPê° command lineì¼ë¡ ëìí ê²½ì° ì¬ì©ë ì ìë ê²ì ê±°ì ìë¤. </simpara> <para> <variablelist> <varlistentry> <term>GATEWAY_INTERFACE</term> <listitem> <simpara> ìë²ê° ì¬ì©íê³ ìë CGI specificationì revision. ì: 'CGI/1.1'. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_NAME</term> <listitem> <simpara> íì¬ ì¤í¬ë¦½í¸ê° ì¤íëê³ ìë í¸ì¤í¸ì ì´ë¦. ë§ì½ ì¤í¬ë¦½í¸ê° ê°ì í¸ì¤í¸ìì ì¤íëê³ ìë¤ë©´, ì´ ê°ì ê°ì í¸ì¤í¸ì ê°ì´ ë ê²ì´ë¤. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_SOFTWARE</term> <listitem> <simpara> ì구ì ëí ëëµì í¤ëì ì¬ì©í ìë² identification 문ìì´ </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_PROTOCOL</term> <listitem> <simpara> íì´ì§ê° ì구ëì´ì§ ë ì¬ì©í íë¡í ì½ì ì´ë¦ê³¼ 리ë¹ì ¼. ì: 'HTTP/1.0'; </simpara> </listitem> </varlistentry> <varlistentry> <term>REQUEST_METHOD</term> <listitem> <simpara> Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'. </simpara> </listitem> </varlistentry> <varlistentry> <term>QUERY_STRING</term> <listitem> <simpara> í´ë¹ íì´ì§ë¥¼ ì ê·¼í ë ì¬ì©ë query string. </simpara> </listitem> </varlistentry> <varlistentry> <term>DOCUMENT_ROOT</term> <listitem> <simpara> íì¬ ì¤í¬ë¦½í¸ê° ìíì¤ì¸ document root ëë í 리. ìë²ì ì¤ì íì¼ì ì ìëì´ ìë¤. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_ACCEPT</term> <listitem> <simpara> Contents of the <literal>Accept:</literal> header from the current request, if there is one. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_ACCEPT_CHARSET</term> <listitem> <simpara> Contents of the <literal>Accept-Charset:</literal> header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_ENCODING</term> <listitem> <simpara> Contents of the <literal>Accept-Encoding:</literal> header from the current request, if there is one. Example: 'gzip'. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_ACCEPT_LANGUAGE</term> <listitem> <simpara> Contents of the <literal>Accept-Language:</literal> header from the current request, if there is one. Example: 'en'. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_CONNECTION</term> <listitem> <simpara> Contents of the <literal>Connection:</literal> header from the current request, if there is one. Example: 'Keep-Alive'. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_HOST</term> <listitem> <simpara> Contents of the <literal>Host:</literal> header from the current request, if there is one. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_REFERER</term> <listitem> <simpara> The address of the page (if any) which referred the browser to the current page. This is set by the user's browser; not all browsers will set this. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_USER_AGENT</term> <listitem> <simpara> Contents of the <literal>User_Agent:</literal> header from the current request, if there is one. This is a string denoting the browser software being used to view the current page; i.e. <computeroutput>Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)</computeroutput>. Among other things, you can use this value with <function>get_browser</function> to tailor your page's functionality to the capabilities of the user's browser. </simpara> </listitem> </varlistentry> <varlistentry> <term>REMOTE_ADDR</term> <listitem> <simpara> The IP address from which the user is viewing the current page. </simpara> </listitem> </varlistentry> <varlistentry> <term>REMOTE_PORT</term> <listitem> <simpara> The port being used on the user's machine to communicate with the web server. </simpara> </listitem> </varlistentry> <varlistentry> <term>SCRIPT_FILENAME</term> <listitem> <simpara> The absolute pathname of the currently executing script. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_ADMIN</term> <listitem> <simpara> The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_PORT</term> <listitem> <simpara> The port on the server machine being used by the web server for communication. For default setups, this will be '80'; using SSL, for instance, will change this to whatever your defined secure HTTP port is. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_SIGNATURE</term> <listitem> <simpara> String containing the server version and virtual host name which are added to server-generated pages, if enabled. </simpara> </listitem> </varlistentry> <varlistentry> <term>PATH_TRANSLATED</term> <listitem> <simpara> Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping. </simpara> </listitem> </varlistentry> <varlistentry> <term>SCRIPT_NAME</term> <listitem> <simpara> Contains the current script's path. This is useful for pages which need to point to themselves. </simpara> </listitem> </varlistentry> <varlistentry> <term>REQUEST_URI</term> <listitem> <simpara> The URI which was given in order to access this page; for instance, '/index.html'. </simpara> </listitem> </varlistentry> </variablelist> </para> </sect2> <sect2 id="language.variables.predefined.environment"> <title>Environment variables</title> <simpara> These variables are imported into PHP's global namespace from the environment under which the PHP parser is running. Many are provided by the shell under which PHP is running and different systems are likely running different kinds of shells, a definitive list is impossible. Please see your shell's documentation for a list of defined environment variables. </simpara> <simpara> Other environment variables include the CGI variables, placed there regardless of whether PHP is running as a server module or CGI processor. </simpara> </sect2> <sect2 id="language.variables.predefined.php"> <title>PHP variables</title> <simpara> These variables are created by PHP itself. The <varname>$HTTP_*_VARS</varname> variables are available only if the <link linkend="ini.track-vars">track_vars</link> configuration is turned on. </simpara> <note> <para> As of PHP 4.0.3, <link linkend="ini.track-vars">track_vars</link> is always turned on, regardless of the configuration file setting. </para> </note> <para> If the <link linkend="ini.register-globals">register_globals</link> directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the <varname>$HTTP_*_VARS</varname> arrays. This feature should be used with care, and turned off if possible; while the <varname>$HTTP_*_VARS</varname> variables are safe, the bare global equivalents can be overwritten by user input, with possibly malicious intent. If you cannot turn off <link linkend="ini.register-globals">register_globals</link>, you must take whatever steps are necessary to ensure that the data you are using is safe. </para> <para> <variablelist> <varlistentry> <term>argv</term> <listitem> <simpara> Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string. </simpara> </listitem> </varlistentry> <varlistentry> <term>argc</term> <listitem> <simpara> Contains the number of command line parameters passed to the script (if run on the command line). </simpara> </listitem> </varlistentry> <varlistentry> <term>PHP_SELF</term> <listitem> <simpara> The filename of the currently executing script, relative to the document root. If PHP is running as a command-line processor, this variable is not available. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_COOKIE_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script via HTTP cookies. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_GET_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script via the HTTP GET method. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_POST_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script via the HTTP POST method. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_POST_FILES</term> <listitem> <simpara> An associative array of variables containing information about files uploaded via the HTTP POST method. See <link linkend="features.file-upload.post-method">POST method uploads</link> for information on the contents of <varname>$HTTP_POST_FILES</varname>. </simpara> <para> <varname>$HTTP_POST_FILES</varname> is available only in PHP 4.0.0 and later. </para> </listitem> </varlistentry> <varlistentry> <term>HTTP_ENV_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script via the parent environment. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_SERVER_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script from the HTTP server. These variables are analogous to the Apache variables described above. </simpara> </listitem> </varlistentry> </variablelist> </para> </sect2> </sect1> <sect1 id="language.variables.scope"> <title>ë³ì ì¬ì© ë²ì (Variable Scope)</title> <simpara> ë³ìê° ì¬ì©ê°ë¥í ê³³ì ê·¸ ë³ìê° ì ì¸ë ê³³ ììì ë§ì´ë¤. PHP ë³ìì ëë¶ë¶ì í ê°ì ë²ì(single scope)ë§ì ê°ì§ê³ ìë¤. ì´ ë²ìë includeë requireëì´ì ì½íì¨ íì¼ìë ëì¼íê² ì ì©ëë¤. ì를ë¤ì´ : </simpara> <informalexample> <programlisting role="php"> $a = 1; include "b.inc"; </programlisting> </informalexample> <simpara> ììì <varname>$a</varname>ë³ìë <filename>b.inc</filename> ì¤í¬ë¦½í¸ììë ì¬ì©í ì ìë¤. 기본ì ì¼ë¡ í¨ì ììì ì ì¸ë ê²ì í¨ì ìììë§ ì¬ì©ëë ì§ì ë³ìì´ë¤. ëí í¨ì ììì ì¬ì©ëë í¨ìë¤ì 기본ì ì¼ë¡ ì§ì ë³ìë¼ê³ ê°ì íê³ ì°¾ê² ëë¤. ì를 ë¤ì´: </simpara> <informalexample> <programlisting role="php"> $a = 1; /* global scope */ Function Test () { echo $a; /* reference to local scope variable */ } Test (); </programlisting> </informalexample> <simpara> ì´ ì¤í¬ë¦½í¸ë í¨ì ìì <varname>$a</varname> ë³ì를 ì§ìë³ìë¡ ê°ì íìê³ , ì§ìë³ì $aìë ì무 ê°ë ëì ëì§ ìì기 ë문ì ìë¬´ë° ì¶ë ¥ë ëíëì§ ìëë¤. ì´ê²ì Cìë ì½ê° ì°¨ì´ê° ëë ë¶ë¶ì´ë¤. PHPìì ì ìë³ì를 ì¬ì©íë ¤ë©´ ì¬ì©íê³ ì¶ì ì ì ë³ì를 í¨ì ìì global ì ì¸ì í´ ì£¼ì´ì¼ íë¤. ì를 ë¤ì´ : </simpara> <informalexample> <programlisting role="php"> $a = 1; $b = 2; Function Sum () { global $a, $b; $b = $a + $b; } Sum (); echo $b; </programlisting> </informalexample> <simpara> ìì ì¤í¬ë¦½í¸ë "3"ì ì¶ë ¥í ê²ì´ë¤. í¨ì ë´ìì <varname>$a</varname>ì <varname>$b</varname>를 globalë¡ ì ì¸íì¼ë¯ë¡, ì´ í¨ìë´ì $a, $bë ì ì ë³ì를 참조íê² ëë¤. í¨ì ë´ìì ë¤ë£° ì ìë ì ìë³ìì ê°ììë ì íì´ ìë¤. </simpara> <simpara> ì ì ë³ì를 참조íë ë ë²ì§¸ ë°©ë²ì PHPìì í¹ë³í ì ìíê³ ìë $GLOBALSë¼ë ë°°ì´ì ì¬ì©íë ê²ì´ë¤. ìì ì를 ë¤ìê³¼ ê°ì´ ë°ê¿ ì¸ ì ìë¤. : </simpara> <informalexample> <programlisting role="php"> $a = 1; $b = 2; Function Sum () { $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"]; } Sum (); echo $b; </programlisting> </informalexample> <simpara> <varname>$GLOBALS</varname> ë°°ì´ì ë³ìì´ë¦ì´ Keyê° ëê³ , ê·¸ ë³ìì ë´ì©ì´ ê°ì´ ëë ìì를 ê°ì§ associative ë°°ì´ì´ë¤. </simpara> <simpara> ë³ì ë²ìì ê´ë ¨íì¬ ììëì´ì¼ í ë ë¤ë¥¸ ë´ì©ì¼ë¡ <emphasis>ì ì </emphasis> ë³ì(static variable)ê° ìë¤ë¤. ì ì ë³ìë ì§ì í¨ì ë´ììë§ ì¡´ì¬íì§ë§ ì§ì í¨ìê° ì¢ ë£ëì´ë ê·¸ ê°ì ì½ì´ë²ë¦¬ì§ ìê³ ê°ì§ê³ ìë¤. ë¤ì ì를 ë³´ì : </simpara> <informalexample> <programlisting role="php"> Function Test () { $a = 0; echo $a; $a++; } </programlisting> </informalexample> <simpara> This function is quite useless since every time it is called it sets <varname>$a</varname> to <literal>0</literal> and prints "0". The <varname>$a</varname>++ which increments the variable serves no purpose since as soon as the function exits the <varname>$a</varname> variable disappears. To make a useful counting function which will not lose track of the current count, the <varname>$a</varname> variable is declared static: </simpara> <informalexample> <programlisting role="php"> Function Test () { static $a = 0; echo $a; $a++; } </programlisting> </informalexample> <simpara> Now, every time the Test() function is called it will print the value of <varname>$a</varname> and increment it. </simpara> <simpara> ëí ì ì ë³ìë ë¤ìê³¼ ê°ì´ recursionìì ë°ëì íìíë¤. ì¬ê·ì ì¸ í¨ìë ì기 ìì ì í¨ì를 í¸ì¶íë ê²ì ë§íë¤. ì¬ê·ì ì¸ í¨ì를 ì¬ì©í ëë 무í 루íì ë¹ ì§ ì ì기 ë문ì ë§¤ì° ì£¼ì를 ìíë¤. ë°ë¼ì ì¬ë¬ë¶ì ì¬ê· í¸ì¶ì ëë´ë ì ì í ë°©ë²ì ë§ë ¨í´ ëì´ì¼ íë¤. ë¤ìì ê°ë¨í ìì ë 10ë²ì ì¬ê·ì í¸ì¶ì íë¤. ì ì ë³ì <varname>$count</varname>를 ì¬ì©íì¬ ì¤ë¨ë ì기를 ì ì ìë¤. </simpara> <informalexample> <programlisting role="php"> Function Test () { static $count = 0; $count++; echo $count; if ($count < 10) { Test (); } $count--; } </programlisting> </informalexample> </sect1> <sect1 id="language.variables.variable"> <title>ê°ë³ ë³ì (Variable variables)</title> <simpara> ê°ë ë³ìì ì´ë¦ì ë³ê²½í ì ìë¤ë©´ í¸ë¦¬íë¤ê³ ëë ëê° ìë¤. ì´ì ë³ìì ì´ë¦ì ë°ê¾¸ì´ ì¬ì©íë ë°©ë²ì ììë³´ì. ë³´íµì ë³ì ì ì¸ì ë¤ìê³¼ ê°ë¤.: </simpara> <informalexample> <programlisting role="php"> $a = "hello"; </programlisting> </informalexample> <simpara> ê°ë³ ë³ìì ë³ìì ê°ì ê°ì§ ìë ìê³ , ëí ì´ ê°ì ë³ìì ì´ë¦ì¼ë¡ ë¤ë£° ìë ìë¤. ìì ììì $$를 ì¬ì©íë©´ <emphasis>hello</emphasis>ê° ë³ì ì´ë¦ì´ ë ì ìë¤. ì : </simpara> <informalexample> <programlisting role="php"> $$a = "world"; </programlisting> </informalexample> <simpara> ì´ë ê² íë©´ PHPì symbol treeìë "hello"ë¼ë ê°ì ê°ì§ë <varname>$a</varname>ì "world"ë¼ë ê°ì ê°ì§ë <varname>$hello</varname>ì ë ê°ì ë³ìê° ìê¸°ê² ëë¤. ê·¸ë¬ë¯ë¡ ë¤ìê³¼ ê°ì 문ì¥ì : </simpara> <informalexample> <programlisting role="php"> echo "$a ${$a}"; </programlisting> </informalexample> <simpara> ë¤ì 문ì¥ê³¼ ë ê°ì ì¶ë ¥ì ëíë´ê² ëë¤.: </simpara> <informalexample> <programlisting> echo "$a $hello"; </programlisting> </informalexample> <simpara> i.e. ëì ì¶ë ¥: <computeroutput>hello world</computeroutput>. </simpara> <simpara> ê°ë³ ë³ì를 ë°°ì´ê³¼ í¨ê» ì¬ì©íë ¤ë©´, íê°ì§ 모í¸ì± 문ì 를 í´ê²°í´ì¼ íë¤. ê·¸ê²ì, ë§ì½ ì¬ë¬ë¶ì´ <varname>$$a[1]</varname>ì´ë¼ê³ ì¼ì¼ë©´, <varname>$a[1]</varname>ì íëì ë³ìë¡ ë³¼ ê²ì¸ì§, ìëë©´ <varname>$$a</varname>를 ë³ìë¡ ë³´ê³ ê·¸ ë³ìì [1]ì ì¸ë±ì¤ë¥¼ í´ ì¤ ê²ì¸ê° íë 문ì ì´ë¤. ë¤ìê³¼ ê°ì´ íì¬ ëª¨í¸ì±ì í´ê²°íì. ì ìì ê²½ì° <varname>${$a[1]}</varname>ë¼ê³ ì°ê³ , íìì ê²½ì°ë <varname>${$a}[1]</varname>ë¼ê³ ì°ë©´ ëë¤. ( ìì주: ê°ë³ ë³ì를 ëíë¼ ëë íì { }ë¡ ëë¬ ì¸ë ê²ì´ 보기 ì¢ê³ ì¤ë¥ë ìì¨ ì ìë¤.) </simpara> </sect1> <sect1 id="language.variables.external"> <title>PHP ë°ìì ì¨ ë³ìë¤ (Variables from outside PHP)</title> <sect2 id="language.variables.external.form"> <title>HTML Forms (GET and POST)</title> <simpara> í¼ì´ PHP ì¤í¬ë¦½í¸ë¡ submitëë©´ í¼ì ìë 모ë ë´ì©ë¤ì´ ìëì ì¼ë¡ ë§ë¤ì´ì§ PHP ë³ìë¡ ë¤ì´ì¨ë¤. ë§ì½ <link linkend="ini.track-vars">track_vars</link> ìµì ì´ onì¼ë¡ ì¤ì ëì´ ìì¼ë©´, ì´ ë³ìë¤ ëª¨ëë ê·¸ê²ì´ ì´ëì ë§ë¤ì´ì§ ê²ì´ëì ë°ë¼ì <varname>$HTTP_POST_VARS</varname>, <varname>$HTTP_GET_VARS</varname>, <varname>$HTTP_POST_FILES</varname>ì associative ë°°ì´ì ìì¹íê² ëë¤. </simpara> <para> ì´ ë³ììëí ìì¸í ì¤ëª ì <link linkend="language.variables.predefined">미리 ì ìë ë³ì (Predefined variables)</link>ì ì½ì´ë³´ê¸° ë°ëë¤. </para> <para> <example> <title>Simple form variable</title> <programlisting role="php"> <form action="foo.php" method="post"> Name: <input type="text" name="username"><br> <input type="submit"> </form> </programlisting> </example> </para> <para> When the above form is submitted, the value from the text input will be available in <varname>$HTTP_POST_VARS['username']</varname>. If the <link linkend="ini.register-globals">register_globals</link> configuration directive is turned on, then the variable will also be available as <varname>$username</varname> in the global scope. </para> <simpara> PHP also understands arrays in the context of form variables. You may, for example, group related variables together, or use this feature to retrieve values from a multiple select input: </simpara> <para> <example> <title>More complex form variables</title> <programlisting role="php"> <form action="array.php" method="post"> Name: <input type="text" name="personal[name]"><br> Email: <input type="text" name="personal[email]"><br> Beer: <br> <select multiple name="beer[]"> <option value="warthog">Warthog <option value="guinness">Guinness <option value="stuttgarter">Stuttgarter Schwabenbräu </select> <input type="submit"> </form> </programlisting> </example> </para> <para> In PHP 3, the array form variable usage is limited to single-dimensional arrays. In PHP 4, no such restriction applies. </para> <sect3 id="language.variables.external.form.submit"> <title>IMAGE SUBMITì ë³ì ì´ë¦</title> <simpara> í¼ì submití ë ì¼ë°ì ì¼ë¡ ì¬ì©íë submit ë²í¼ ëì ë¤ìê³¼ ê°ì´ 그림ì ì¬ì©í ìë ìë¤. : </simpara> <informalexample> <programlisting role="php"> <input type=image src="image.gif" name="sub"> </programlisting> </informalexample> <simpara> ì¬ì©ìê° image를 í´ë¦íë©´, í¼ì sub_xì sub_yì ë ê°ì ë³ìê° ì¶ê°ëì´ ìë²ì ì ì¡ëë¤. ì´ ë ë³ìë ì´ë¯¸ì§ìì ì¬ì©ìê° clickí ìì¹ ì 보를 ë´ê³ ìë¤. ì¼ë¶ ë¸ë¼ì°ì ììë ë°ì¤(_)ëì ë§ì¹¨í(.)를 ì¬ì©íë ê²½ì°ë ìëë°, PHPë ì´ë° ê²½ì° ìëì ì ë§ì¹¨í(.)를 ë°ì¤(_)ë¡ ë°ê¿ì¤ë¤. </simpara> </sect3> </sect2> <sect2 id="language.variables.external.cookies"> <title>HTTP Cookies</title> <simpara> PHPë HTTP ì¿ í¤ë¥¼ <ulink url="&spec.cookies;">Netscape's Spec</ulink>ì ì ìì ë°ë¼ ì ê³µíë¤. Cookie ë©ì¹´ëì¦ì í¸ëí¹ì´ë ì¬ì©ì ìë³ ë±ì ìí´ ì격 browserì ì ì¥ë ë°ì´í°ë¥¼ ëë ¤ ë°ë ê³¼ì ì ë§íë¤. ì¬ë¬ë¶ì cookie를 ì¤ì í기 ìí´ <function>SetCookie</function>í¨ì를 ì¬ì©í ì ìë¤. Cookieë HTTP í¤ëì í ë¶ë¶ì´ë¯ë¡, <function>SetCookie</function> í¨ìë ë¸ë¼ì°ì ë¡ ë³´ë´ë ì´ë¤ ë°ì´í°ë³´ë¤ë ìì ì¬ì©í´ì¼ íë¤. ì´ ì ì½ì <function>Header</function> í¨ìì ê°ì ì ì½ì¼ë¡ ë³´ë©´ ëë¤. ë³´ë¸ ëª¨ë cookieë ìëì ì¼ë¡ GETì´ë POST ë°©ì ë°ì´í°ì ê°ì PHP ë³ìë¡ ë³íëë¤. </simpara> <simpara> ë§ì½ ì¬ë¬ë¶ì´ ëì¼í cookieì ì¬ë¬ ê°ì ì ì¥íê³ ì¶ë¤ë©´ Cookieì´ë¦ì <emphasis>[]</emphasis>를 ëíë©´ ëë¤. ì를 ë¤ì´ : </simpara> <informalexample> <programlisting role="php"> SetCookie ("MyCookie[]", "Testing", time()+3600); </programlisting> </informalexample> <simpara> ì¿ í¤ë ìë¡ ì¤ì íë©´ pathë ëë©ì¸ì´ ë¤ë¥´ì§ ìë í ì´ì ì ì¿ í¤ë¥¼ ë®ì´ì°ê² ëë¤. ê·¸ë¬ë¯ë¡ ì¼í ì¹´í¸ ê°ì ìì© íë¡ê·¸ë¨ììë ë¤ìê³¼ ê°ì´ ì¹´ì´í°ë¥¼ ì¬ì©íì¬, ì´ê²ì 기ì¤ì¼ë¡ Cookie를 ì¬ì©íë ê²ì´ ì¢ë¤. ì : </simpara> <example> <title>SetCookie Example</title> <programlisting role="php"> $Count++; SetCookie ("Count", $Count, time()+3600); SetCookie ("Cart[$Count]", $item, time()+3600); </programlisting> </example> </sect2> <sect2 id="language.variables.external.environment"> <title>íê²½ ë³ì (Environment variables)</title> <para> PHPë ìëì ì¼ë¡ íê²½ ë³ìë¤ì ì¼ë°ì ì¸ PHP ë³ìë¡ ë§ë ë¤. <informalexample> <programlisting role="php"> echo $HOME; /* Shows the HOME environment variable, if set. */ </programlisting> </informalexample> </para> <para> GET, POST, Cookie ë©ì¹´ëì¦ì íµí´ì ë¤ì´ ì¨ ì ë³´ë¡ë¶í°ë PHP ë³ìê° ì기ë¯ë¡, ëëë¡ íê²½ë³ìë¡ë¶í° ë°ìê²ì´ íì¤íê°ë¥¼ íì¸í íìê° ìì ëë ìë¤. ì´ë¥¼ ìí´ <function>getenv</function> í¨ì를 ì¬ì©íë¤. íê²½ ë³ì를 ì¤ì í기 ìí´ìë <function>putenv</function> í¨ì를 ì¬ì©íë¤. </para> </sect2> <sect2 id="language.variables.external.dot-in-names"> <title>ì¸ë¶ ë³ìëª ì ìë '.' (Dots in incoming variable names)</title> <para> ì¼ë°ì ì¼ë¡ PHPë ë³ì를 ì¤í¬ë¦½í¸ë¡ ê°ì ¸ì¬ ë ë³ìëª ì ë°ê¾¸ì§ ìëë¤. ê·¸ë¬ë, PHPì ë³ìëª ìë '.' (ì )ì ì¬ì©í ì ìë¤. ë¤ìê³¼ ê°ì ê²½ì°ë¥¼ ë³´ì. : <programlisting role="php"> $varname.ext; /* invalid variable name */ </programlisting> ìì ê²½ì° PHP íìë <varname>$varname</varname>ì´ë¼ë ë³ìì, ì°ê²° ì°ì°ì, 'ext'(ë°ì´íê° ìë ê²½ì° ê·¸ê²ì´ ì´ë¤ ìë ¤ì§ í¤ë ìì½ì´ê° ìëë©´ 문ìì´ë¡ ì·¨ê¸ëë¤.)ë¡ í´ìíë¤. ì´ê²ì ì°ë¦¬ê° ìíë ê²°ê³¼ê° ìëë¤. </para> <para> ìì ê°ì ì´ì ë¡ PHPë ì¸ë¶ìì ë¶ë¬ë¤ì¸ ë³ìì ì´ë¦ì '.'ì´ ìì¼ë©´ '_'(ë°ì¤)ë¡ ë°ê¾¸ì´ ì½ì´ë¤ì¸ë¤. </para> </sect2> <sect2 id="language.variables.determining-type-of"> <title>ë³ìì Type íë¨ (Determining variable types)</title> <para> PHPë ë³ìì typeì ììì ì íê³ (ì¼ë°ì ì¼ë¡) íìí ê²½ì°ìë ê·¸ typeì ë°ê¾¸ë¯ë¡, í¹ì ìì ì ê·¸ ë³ì ì´ë¤ typeì¸ì§ë ì½ê² ì ì ìë¤. PHPë ë³ìì typeì ìì보기 ìí´ ì¬ë¬ê°ì í¨ì를 ê°ì§ê³ ìë¤. <function>gettype</function>, <function>is_long</function>, <function>is_double</function>, <function>is_string</function>, <function>is_array</function>, <function>is_object</function> ê° ê·¸ê²ë¤ì´ë¤. </para> </sect2> </sect1> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: -->
Index: phpdoc/kr/language/variables.xml +++ phpdoc/kr/language/variables.xml <chapter id="language.variables"> <title>ë³ì (Variables)</title> <sect1 id="language.variables.basics"> <title>기본(Basics)</title> <simpara> Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. </simpara> <para> Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' </para> <note> <simpara> For our purposes here, a letter is a-z, A-Z, and the ASCII characters from 127 through 255 (0x7f-0xff). </simpara> </note> <para> <informalexample> <programlisting role="php"> $var = "Bob"; $Var = "Joe"; echo "$var, $Var"; // outputs "Bob, Joe" $4site = 'not yet'; // invalid; starts with a number $_4site = 'not yet'; // valid; starts with an underscore $t㸴e = 'mansikka'; // valid; '⥠is ASCII 228. </programlisting> </informalexample> </para> <para> In PHP 3, variables are always assigned by value. That is to say, when you assign an expression to a variable, the entire value of the original expression is copied into the destination variable. This means, for instance, that after assigning one variable's value to another, changing one of those variables will have no effect on the other. For more information on this kind of assignment, see <link linkend="language.expressions">Expressions</link>. </para> <para> PHP 4 offers another way to assign values to variables: <emphasis>assign by reference</emphasis>. This means that the new variable simply references (in other words, "becomes an alias for" or "points to") the original variable. Changes to the new variable affect the original, and vice versa. This also means that no copying is performed; thus, the assignment happens more quickly. However, any speedup will likely be noticed only in tight loops or when assigning large arrays or objects. </para> <para> To assign by reference, simply prepend an ampersand (&) to the beginning of the variable which is being assigned (the source variable). For instance, the following code snippet outputs 'My name is Bob' twice: <informalexample> <programlisting role="php"> <?php $foo = 'Bob'; // Assign the value 'Bob' to $foo $bar = &$foo; // Reference $foo via $bar. $bar = "My name is $bar"; // Alter $bar... echo $foo; // $foo is altered too. echo $bar; ?> </programlisting> </informalexample> </para> <para> One important thing to note is that only named variables may be assigned by reference. <informalexample> <programlisting role="php"> <?php $foo = 25; $bar = &$foo; // This is a valid assignment. $bar = &(24 * 7); // Invalid; references an unnamed expression. function test() { return 25; } $bar = &test(); // Invalid. ?> </programlisting> </informalexample> </para> </sect1> <sect1 id="language.variables.predefined"> <title>미리 ì ìë ë³ì (Predefined variables)</title> <simpara> PHPë 모ë ì¤í¬ë¦½í¸ì ëí´ ê·¸ ì¤í¬ë¦½í¸ê° ì¤í ë ë ì¬ë¬ê°ì 미리 ì ìë ë³ì를 ì ê³µíë¤. ì´ ë³ìì¤ ìë²ì ì¢ ë¥ë ë²ì , 기í ë¤ë¥¸ ìì¸ì¼ë¡ ì¸í´ ë¬ë¼ì§ë ê²ë ë§ìë°, ê·¸ë° ë³ìë ì´ê³³ì 문ìí ëì§ ììë¤. ëí ì´ ë³ìì¤ ë¤ìë PHPê° command-lineì¼ë¡ ëìí ëë ì¬ì©í ì ìë¤. </simpara> <simpara> ì´ë° ì¬ë¬ ìì¸ì´ ìì§ë§ ì´ê³³ììë ê°ì¥ ì¼ë°ì ì¸ íê²½ì¸ <ulink url="&url.apache;">Apache</ulink> 1.3.6 ìì 모ëë¡ PHP3를 ì¤ì¹í íê²½ììì 미리 ì ìë ë³ì를 ì´í´ë³´ëë¡ íì. </simpara> <simpara> ì¬ë¬ë¶ì´ ì¬ì©íë ìì¤í ì 모ë 미리 ì ìë ë³ì를 ë³´ë ¤ë©´ <function>phpinfo</function> í¨ì를 ì¬ì©íì. (ì´ í¨ìë ë¤ë¥¸ ì¬ë¬ ì ì©í ì ë³´ë ìë ¤ì¤ë¤.) </simpara> <note> <simpara> ì¬ê¸°ëì¨ ëª©ë¡ì ìì íì§ ìë¤. (ìë²½í ìê°ë ìë¤.) ì´ ëª©ë¡ì ë¨ìí ì¬ë¬ë¶ì ì¤í¬ë¦½í¸ìì ì´ë¤ ì¢ ë¥ì 미리 ì ìë ë³ìê° ì¬ì©ë ì ìëê°ì ììì¼ ë¿ì´ë¤. </simpara> </note> <sect2 id="language.variables.predefined.apache"> <title>Apache variables</title> <simpara> ì´ ë³ìë <ulink url="&url.apache;">Apache</ulink> ì¹ìë²ë¡ë¶í° ìì±ë ê²ì´ë¤. ë§ì½ ì¬ë¬ë¶ì´ ë¤ë¥¸ ì¹ìë²ë¥¼ ì¬ì©íê³ ìë¤ë©´ ì´ì ëì¼í ë³ìê° ìì±ëë¤ê³ ë³´ì¥í ì ìë¤. ìë§ë ì¼ë¶ë ìì´ì§ê³ , ì¬ê¸°ì ìë ë³ìê° ìë¡ ì길 ê²ì´ë¤. ì¬ê¸°ì ìë ë³ìì¤ ëë¶ë¶ì <ulink url="&url.cgispec;">CGI 1.1 specification</ulink>ìì ëì¨ ê²ì´ê³ , ê·¸ ë´ì©ëë¡ ì¬ì©ëë¤. </simpara> <simpara> ì´ê³³ì ìë ë³ìì¤ PHPê° command lineì¼ë¡ ëìí ê²½ì° ì¬ì©ë ì ìë ê²ì ê±°ì ìë¤. </simpara> <para> <variablelist> <varlistentry> <term>GATEWAY_INTERFACE</term> <listitem> <simpara> ìë²ê° ì¬ì©íê³ ìë CGI specificationì revision. ì: 'CGI/1.1'. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_NAME</term> <listitem> <simpara> íì¬ ì¤í¬ë¦½í¸ê° ì¤íëê³ ìë í¸ì¤í¸ì ì´ë¦. ë§ì½ ì¤í¬ë¦½í¸ê° ê°ì í¸ì¤í¸ìì ì¤íëê³ ìë¤ë©´, ì´ ê°ì ê°ì í¸ì¤í¸ì ê°ì´ ë ê²ì´ë¤. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_SOFTWARE</term> <listitem> <simpara> ì구ì ëí ëëµì í¤ëì ì¬ì©í ìë² identification 문ìì´ </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_PROTOCOL</term> <listitem> <simpara> íì´ì§ê° ì구ëì´ì§ ë ì¬ì©í íë¡í ì½ì ì´ë¦ê³¼ 리ë¹ì ¼. ì: 'HTTP/1.0'; </simpara> </listitem> </varlistentry> <varlistentry> <term>REQUEST_METHOD</term> <listitem> <simpara> Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'. </simpara> </listitem> </varlistentry> <varlistentry> <term>QUERY_STRING</term> <listitem> <simpara> í´ë¹ íì´ì§ë¥¼ ì ê·¼í ë ì¬ì©ë query string. </simpara> </listitem> </varlistentry> <varlistentry> <term>DOCUMENT_ROOT</term> <listitem> <simpara> íì¬ ì¤í¬ë¦½í¸ê° ìíì¤ì¸ document root ëë í 리. ìë²ì ì¤ì íì¼ì ì ìëì´ ìë¤. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_ACCEPT</term> <listitem> <simpara> Contents of the <literal>Accept:</literal> header from the current request, if there is one. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_ACCEPT_CHARSET</term> <listitem> <simpara> Contents of the <literal>Accept-Charset:</literal> header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_ENCODING</term> <listitem> <simpara> Contents of the <literal>Accept-Encoding:</literal> header from the current request, if there is one. Example: 'gzip'. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_ACCEPT_LANGUAGE</term> <listitem> <simpara> Contents of the <literal>Accept-Language:</literal> header from the current request, if there is one. Example: 'en'. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_CONNECTION</term> <listitem> <simpara> Contents of the <literal>Connection:</literal> header from the current request, if there is one. Example: 'Keep-Alive'. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_HOST</term> <listitem> <simpara> Contents of the <literal>Host:</literal> header from the current request, if there is one. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_REFERER</term> <listitem> <simpara> The address of the page (if any) which referred the browser to the current page. This is set by the user's browser; not all browsers will set this. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_USER_AGENT</term> <listitem> <simpara> Contents of the <literal>User_Agent:</literal> header from the current request, if there is one. This is a string denoting the browser software being used to view the current page; i.e. <computeroutput>Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)</computeroutput>. Among other things, you can use this value with <function>get_browser</function> to tailor your page's functionality to the capabilities of the user's browser. </simpara> </listitem> </varlistentry> <varlistentry> <term>REMOTE_ADDR</term> <listitem> <simpara> The IP address from which the user is viewing the current page. </simpara> </listitem> </varlistentry> <varlistentry> <term>REMOTE_PORT</term> <listitem> <simpara> The port being used on the user's machine to communicate with the web server. </simpara> </listitem> </varlistentry> <varlistentry> <term>SCRIPT_FILENAME</term> <listitem> <simpara> The absolute pathname of the currently executing script. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_ADMIN</term> <listitem> <simpara> The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_PORT</term> <listitem> <simpara> The port on the server machine being used by the web server for communication. For default setups, this will be '80'; using SSL, for instance, will change this to whatever your defined secure HTTP port is. </simpara> </listitem> </varlistentry> <varlistentry> <term>SERVER_SIGNATURE</term> <listitem> <simpara> String containing the server version and virtual host name which are added to server-generated pages, if enabled. </simpara> </listitem> </varlistentry> <varlistentry> <term>PATH_TRANSLATED</term> <listitem> <simpara> Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping. </simpara> </listitem> </varlistentry> <varlistentry> <term>SCRIPT_NAME</term> <listitem> <simpara> Contains the current script's path. This is useful for pages which need to point to themselves. </simpara> </listitem> </varlistentry> <varlistentry> <term>REQUEST_URI</term> <listitem> <simpara> The URI which was given in order to access this page; for instance, '/index.html'. </simpara> </listitem> </varlistentry> </variablelist> </para> </sect2> <sect2 id="language.variables.predefined.environment"> <title>Environment variables</title> <simpara> These variables are imported into PHP's global namespace from the environment under which the PHP parser is running. Many are provided by the shell under which PHP is running and different systems are likely running different kinds of shells, a definitive list is impossible. Please see your shell's documentation for a list of defined environment variables. </simpara> <simpara> Other environment variables include the CGI variables, placed there regardless of whether PHP is running as a server module or CGI processor. </simpara> </sect2> <sect2 id="language.variables.predefined.php"> <title>PHP variables</title> <simpara> These variables are created by PHP itself. The <varname>$HTTP_*_VARS</varname> variables are available only if the <link linkend="ini.track-vars">track_vars</link> configuration is turned on. </simpara> <note> <para> As of PHP 4.0.3, <link linkend="ini.track-vars">track_vars</link> is always turned on, regardless of the configuration file setting. </para> </note> <para> If the <link linkend="ini.register-globals">register_globals</link> directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the <varname>$HTTP_*_VARS</varname> arrays. This feature should be used with care, and turned off if possible; while the <varname>$HTTP_*_VARS</varname> variables are safe, the bare global equivalents can be overwritten by user input, with possibly malicious intent. If you cannot turn off <link linkend="ini.register-globals">register_globals</link>, you must take whatever steps are necessary to ensure that the data you are using is safe. </para> <para> <variablelist> <varlistentry> <term>argv</term> <listitem> <simpara> Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string. </simpara> </listitem> </varlistentry> <varlistentry> <term>argc</term> <listitem> <simpara> Contains the number of command line parameters passed to the script (if run on the command line). </simpara> </listitem> </varlistentry> <varlistentry> <term>PHP_SELF</term> <listitem> <simpara> The filename of the currently executing script, relative to the document root. If PHP is running as a command-line processor, this variable is not available. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_COOKIE_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script via HTTP cookies. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_GET_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script via the HTTP GET method. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_POST_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script via the HTTP POST method. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_POST_FILES</term> <listitem> <simpara> An associative array of variables containing information about files uploaded via the HTTP POST method. See <link linkend="features.file-upload.post-method">POST method uploads</link> for information on the contents of <varname>$HTTP_POST_FILES</varname>. </simpara> <para> <varname>$HTTP_POST_FILES</varname> is available only in PHP 4.0.0 and later. </para> </listitem> </varlistentry> <varlistentry> <term>HTTP_ENV_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script via the parent environment. </simpara> </listitem> </varlistentry> <varlistentry> <term>HTTP_SERVER_VARS</term> <listitem> <simpara> An associative array of variables passed to the current script from the HTTP server. These variables are analogous to the Apache variables described above. </simpara> </listitem> </varlistentry> </variablelist> </para> </sect2> </sect1> <sect1 id="language.variables.scope"> <title>ë³ì ì¬ì© ë²ì (Variable Scope)</title> <simpara> ë³ìê° ì¬ì©ê°ë¥í ê³³ì ê·¸ ë³ìê° ì ì¸ë ê³³ ììì ë§ì´ë¤. PHP ë³ìì ëë¶ë¶ì í ê°ì ë²ì(single scope)ë§ì ê°ì§ê³ ìë¤. ì´ ë²ìë includeë requireëì´ì ì½íì¨ íì¼ìë ëì¼íê² ì ì©ëë¤. ì를ë¤ì´ : </simpara> <informalexample> <programlisting role="php"> $a = 1; include "b.inc"; </programlisting> </informalexample> <simpara> ììì <varname>$a</varname>ë³ìë <filename>b.inc</filename> ì¤í¬ë¦½í¸ììë ì¬ì©í ì ìë¤. 기본ì ì¼ë¡ í¨ì ììì ì ì¸ë ê²ì í¨ì ìììë§ ì¬ì©ëë ì§ì ë³ìì´ë¤. ëí í¨ì ììì ì¬ì©ëë í¨ìë¤ì 기본ì ì¼ë¡ ì§ì ë³ìë¼ê³ ê°ì íê³ ì°¾ê² ëë¤. ì를 ë¤ì´: </simpara> <informalexample> <programlisting role="php"> $a = 1; /* global scope */ Function Test () { echo $a; /* reference to local scope variable */ } Test (); </programlisting> </informalexample> <simpara> ì´ ì¤í¬ë¦½í¸ë í¨ì ìì <varname>$a</varname> ë³ì를 ì§ìë³ìë¡ ê°ì íìê³ , ì§ìë³ì $aìë ì무 ê°ë ëì ëì§ ìì기 ë문ì ìë¬´ë° ì¶ë ¥ë ëíëì§ ìëë¤. ì´ê²ì Cìë ì½ê° ì°¨ì´ê° ëë ë¶ë¶ì´ë¤. PHPìì ì ìë³ì를 ì¬ì©íë ¤ë©´ ì¬ì©íê³ ì¶ì ì ì ë³ì를 í¨ì ìì global ì ì¸ì í´ ì£¼ì´ì¼ íë¤. ì를 ë¤ì´ : </simpara> <informalexample> <programlisting role="php"> $a = 1; $b = 2; Function Sum () { global $a, $b; $b = $a + $b; } Sum (); echo $b; </programlisting> </informalexample> <simpara> ìì ì¤í¬ë¦½í¸ë "3"ì ì¶ë ¥í ê²ì´ë¤. í¨ì ë´ìì <varname>$a</varname>ì <varname>$b</varname>를 globalë¡ ì ì¸íì¼ë¯ë¡, ì´ í¨ìë´ì $a, $bë ì ì ë³ì를 참조íê² ëë¤. í¨ì ë´ìì ë¤ë£° ì ìë ì ìë³ìì ê°ììë ì íì´ ìë¤. </simpara> <simpara> ì ì ë³ì를 참조íë ë ë²ì§¸ ë°©ë²ì PHPìì í¹ë³í ì ìíê³ ìë $GLOBALSë¼ë ë°°ì´ì ì¬ì©íë ê²ì´ë¤. ìì ì를 ë¤ìê³¼ ê°ì´ ë°ê¿ ì¸ ì ìë¤. : </simpara> <informalexample> <programlisting role="php"> $a = 1; $b = 2; Function Sum () { $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"]; } Sum (); echo $b; </programlisting> </informalexample> <simpara> <varname>$GLOBALS</varname> ë°°ì´ì ë³ìì´ë¦ì´ Keyê° ëê³ , ê·¸ ë³ìì ë´ì©ì´ ê°ì´ ëë ìì를 ê°ì§ associative ë°°ì´ì´ë¤. </simpara> <simpara> ë³ì ë²ìì ê´ë ¨íì¬ ììëì´ì¼ í ë ë¤ë¥¸ ë´ì©ì¼ë¡ <emphasis>ì ì </emphasis> ë³ì(static variable)ê° ìë¤ë¤. ì ì ë³ìë ì§ì í¨ì ë´ììë§ ì¡´ì¬íì§ë§ ì§ì í¨ìê° ì¢ ë£ëì´ë ê·¸ ê°ì ì½ì´ë²ë¦¬ì§ ìê³ ê°ì§ê³ ìë¤. ë¤ì ì를 ë³´ì : </simpara> <informalexample> <programlisting role="php"> Function Test () { $a = 0; echo $a; $a++; } </programlisting> </informalexample> <simpara> This function is quite useless since every time it is called it sets <varname>$a</varname> to <literal>0</literal> and prints "0". The <varname>$a</varname>++ which increments the variable serves no purpose since as soon as the function exits the <varname>$a</varname> variable disappears. To make a useful counting function which will not lose track of the current count, the <varname>$a</varname> variable is declared static: </simpara> <informalexample> <programlisting role="php"> Function Test () { static $a = 0; echo $a; $a++; } </programlisting> </informalexample> <simpara> Now, every time the Test() function is called it will print the value of <varname>$a</varname> and increment it. </simpara> <simpara> ëí ì ì ë³ìë ë¤ìê³¼ ê°ì´ recursionìì ë°ëì íìíë¤. ì¬ê·ì ì¸ í¨ìë ì기 ìì ì í¨ì를 í¸ì¶íë ê²ì ë§íë¤. ì¬ê·ì ì¸ í¨ì를 ì¬ì©í ëë 무í 루íì ë¹ ì§ ì ì기 ë문ì ë§¤ì° ì£¼ì를 ìíë¤. ë°ë¼ì ì¬ë¬ë¶ì ì¬ê· í¸ì¶ì ëë´ë ì ì í ë°©ë²ì ë§ë ¨í´ ëì´ì¼ íë¤. ë¤ìì ê°ë¨í ìì ë 10ë²ì ì¬ê·ì í¸ì¶ì íë¤. ì ì ë³ì <varname>$count</varname>를 ì¬ì©íì¬ ì¤ë¨ë ì기를 ì ì ìë¤. </simpara> <informalexample> <programlisting role="php"> Function Test () { static $count = 0; $count++; echo $count; if ($count < 10) { Test (); } $count--; } </programlisting> </informalexample> </sect1> <sect1 id="language.variables.variable"> <title>ê°ë³ ë³ì (Variable variables)</title> <simpara> ê°ë ë³ìì ì´ë¦ì ë³ê²½í ì ìë¤ë©´ í¸ë¦¬íë¤ê³ ëë ëê° ìë¤. ì´ì ë³ìì ì´ë¦ì ë°ê¾¸ì´ ì¬ì©íë ë°©ë²ì ììë³´ì. ë³´íµì ë³ì ì ì¸ì ë¤ìê³¼ ê°ë¤.: </simpara> <informalexample> <programlisting role="php"> $a = "hello"; </programlisting> </informalexample> <simpara> ê°ë³ ë³ìì ë³ìì ê°ì ê°ì§ ìë ìê³ , ëí ì´ ê°ì ë³ìì ì´ë¦ì¼ë¡ ë¤ë£° ìë ìë¤. ìì ììì $$를 ì¬ì©íë©´ <emphasis>hello</emphasis>ê° ë³ì ì´ë¦ì´ ë ì ìë¤. ì : </simpara> <informalexample> <programlisting role="php"> $$a = "world"; </programlisting> </informalexample> <simpara> ì´ë ê² íë©´ PHPì symbol treeìë "hello"ë¼ë ê°ì ê°ì§ë <varname>$a</varname>ì "world"ë¼ë ê°ì ê°ì§ë <varname>$hello</varname>ì ë ê°ì ë³ìê° ìê¸°ê² ëë¤. ê·¸ë¬ë¯ë¡ ë¤ìê³¼ ê°ì 문ì¥ì : </simpara> <informalexample> <programlisting role="php"> echo "$a ${$a}"; </programlisting> </informalexample> <simpara> ë¤ì 문ì¥ê³¼ ë ê°ì ì¶ë ¥ì ëíë´ê² ëë¤.: </simpara> <informalexample> <programlisting> echo "$a $hello"; </programlisting> </informalexample> <simpara> i.e. ëì ì¶ë ¥: <computeroutput>hello world</computeroutput>. </simpara> <simpara> ê°ë³ ë³ì를 ë°°ì´ê³¼ í¨ê» ì¬ì©íë ¤ë©´, íê°ì§ 모í¸ì± 문ì 를 í´ê²°í´ì¼ íë¤. ê·¸ê²ì, ë§ì½ ì¬ë¬ë¶ì´ <varname>$$a[1]</varname>ì´ë¼ê³ ì¼ì¼ë©´, <varname>$a[1]</varname>ì íëì ë³ìë¡ ë³¼ ê²ì¸ì§, ìëë©´ <varname>$$a</varname>를 ë³ìë¡ ë³´ê³ ê·¸ ë³ìì [1]ì ì¸ë±ì¤ë¥¼ í´ ì¤ ê²ì¸ê° íë 문ì ì´ë¤. ë¤ìê³¼ ê°ì´ íì¬ ëª¨í¸ì±ì í´ê²°íì. ì ìì ê²½ì° <varname>${$a[1]}</varname>ë¼ê³ ì°ê³ , íìì ê²½ì°ë <varname>${$a}[1]</varname>ë¼ê³ ì°ë©´ ëë¤. ( ìì주: ê°ë³ ë³ì를 ëíë¼ ëë íì { }ë¡ ëë¬ ì¸ë ê²ì´ 보기 ì¢ê³ ì¤ë¥ë ìì¨ ì ìë¤.) </simpara> </sect1> <sect1 id="language.variables.external"> <title>PHP ë°ìì ì¨ ë³ìë¤ (Variables from outside PHP)</title> <sect2 id="language.variables.external.form"> <title>HTML Forms (GET and POST)</title> <simpara> í¼ì´ PHP ì¤í¬ë¦½í¸ë¡ submitëë©´ í¼ì ìë 모ë ë´ì©ë¤ì´ ìëì ì¼ë¡ ë§ë¤ì´ì§ PHP ë³ìë¡ ë¤ì´ì¨ë¤. ë§ì½ <link linkend="ini.track-vars">track_vars</link> ìµì ì´ onì¼ë¡ ì¤ì ëì´ ìì¼ë©´, ì´ ë³ìë¤ ëª¨ëë ê·¸ê²ì´ ì´ëì ë§ë¤ì´ì§ ê²ì´ëì ë°ë¼ì <varname>$HTTP_POST_VARS</varname>, <varname>$HTTP_GET_VARS</varname>, <varname>$HTTP_POST_FILES</varname>ì associative ë°°ì´ì ìì¹íê² ëë¤. </simpara> <para> ì´ ë³ììëí ìì¸í ì¤ëª ì <link linkend="language.variables.predefined">미리 ì ìë ë³ì (Predefined variables)</link>ì ì½ì´ë³´ê¸° ë°ëë¤. </para> <para> <example> <title>Simple form variable</title> <programlisting role="php"> <form action="foo.php" method="post"> Name: <input type="text" name="username"><br> <input type="submit"> </form> </programlisting> </example> </para> <para> When the above form is submitted, the value from the text input will be available in <varname>$HTTP_POST_VARS['username']</varname>. If the <link linkend="ini.register-globals">register_globals</link> configuration directive is turned on, then the variable will also be available as <varname>$username</varname> in the global scope. </para> <simpara> PHP also understands arrays in the context of form variables. You may, for example, group related variables together, or use this feature to retrieve values from a multiple select input: </simpara> <para> <example> <title>More complex form variables</title> <programlisting role="php"> <form action="array.php" method="post"> Name: <input type="text" name="personal[name]"><br> Email: <input type="text" name="personal[email]"><br> Beer: <br> <select multiple name="beer[]"> <option value="warthog">Warthog <option value="guinness">Guinness <option value="stuttgarter">Stuttgarter Schwabenbräu </select> <input type="submit"> </form> </programlisting> </example> </para> <para> In PHP 3, the array form variable usage is limited to single-dimensional arrays. In PHP 4, no such restriction applies. </para> <sect3 id="language.variables.external.form.submit"> <title>IMAGE SUBMITì ë³ì ì´ë¦</title> <simpara> í¼ì submití ë ì¼ë°ì ì¼ë¡ ì¬ì©íë submit ë²í¼ ëì ë¤ìê³¼ ê°ì´ 그림ì ì¬ì©í ìë ìë¤. : </simpara> <informalexample> <programlisting role="php"> <input type=image src="image.gif" name="sub"> </programlisting> </informalexample> <simpara> ì¬ì©ìê° image를 í´ë¦íë©´, í¼ì sub_xì sub_yì ë ê°ì ë³ìê° ì¶ê°ëì´ ìë²ì ì ì¡ëë¤. ì´ ë ë³ìë ì´ë¯¸ì§ìì ì¬ì©ìê° clickí ìì¹ ì 보를 ë´ê³ ìë¤. ì¼ë¶ ë¸ë¼ì°ì ììë ë°ì¤(_)ëì ë§ì¹¨í(.)를 ì¬ì©íë ê²½ì°ë ìëë°, PHPë ì´ë° ê²½ì° ìëì ì ë§ì¹¨í(.)를 ë°ì¤(_)ë¡ ë°ê¿ì¤ë¤. </simpara> </sect3> </sect2> <sect2 id="language.variables.external.cookies"> <title>HTTP Cookies</title> <simpara> PHPë HTTP ì¿ í¤ë¥¼ <ulink url="&spec.cookies;">Netscape's Spec</ulink>ì ì ìì ë°ë¼ ì ê³µíë¤. Cookie ë©ì¹´ëì¦ì í¸ëí¹ì´ë ì¬ì©ì ìë³ ë±ì ìí´ ì격 browserì ì ì¥ë ë°ì´í°ë¥¼ ëë ¤ ë°ë ê³¼ì ì ë§íë¤. ì¬ë¬ë¶ì cookie를 ì¤ì í기 ìí´ <function>SetCookie</function>í¨ì를 ì¬ì©í ì ìë¤. Cookieë HTTP í¤ëì í ë¶ë¶ì´ë¯ë¡, <function>SetCookie</function> í¨ìë ë¸ë¼ì°ì ë¡ ë³´ë´ë ì´ë¤ ë°ì´í°ë³´ë¤ë ìì ì¬ì©í´ì¼ íë¤. ì´ ì ì½ì <function>Header</function> í¨ìì ê°ì ì ì½ì¼ë¡ ë³´ë©´ ëë¤. ë³´ë¸ ëª¨ë cookieë ìëì ì¼ë¡ GETì´ë POST ë°©ì ë°ì´í°ì ê°ì PHP ë³ìë¡ ë³íëë¤. </simpara> <simpara> ë§ì½ ì¬ë¬ë¶ì´ ëì¼í cookieì ì¬ë¬ ê°ì ì ì¥íê³ ì¶ë¤ë©´ Cookieì´ë¦ì <emphasis>[]</emphasis>를 ëíë©´ ëë¤. ì를 ë¤ì´ : </simpara> <informalexample> <programlisting role="php"> SetCookie ("MyCookie[]", "Testing", time()+3600); </programlisting> </informalexample> <simpara> ì¿ í¤ë ìë¡ ì¤ì íë©´ pathë ëë©ì¸ì´ ë¤ë¥´ì§ ìë í ì´ì ì ì¿ í¤ë¥¼ ë®ì´ì°ê² ëë¤. ê·¸ë¬ë¯ë¡ ì¼í ì¹´í¸ ê°ì ìì© íë¡ê·¸ë¨ììë ë¤ìê³¼ ê°ì´ ì¹´ì´í°ë¥¼ ì¬ì©íì¬, ì´ê²ì 기ì¤ì¼ë¡ Cookie를 ì¬ì©íë ê²ì´ ì¢ë¤. ì : </simpara> <example> <title>SetCookie Example</title> <programlisting role="php"> $Count++; SetCookie ("Count", $Count, time()+3600); SetCookie ("Cart[$Count]", $item, time()+3600); </programlisting> </example> </sect2> <sect2 id="language.variables.external.environment"> <title>íê²½ ë³ì (Environment variables)</title> <para> PHPë ìëì ì¼ë¡ íê²½ ë³ìë¤ì ì¼ë°ì ì¸ PHP ë³ìë¡ ë§ë ë¤. <informalexample> <programlisting role="php"> echo $HOME; /* Shows the HOME environment variable, if set. */ </programlisting> </informalexample> </para> <para> GET, POST, Cookie ë©ì¹´ëì¦ì íµí´ì ë¤ì´ ì¨ ì ë³´ë¡ë¶í°ë PHP ë³ìê° ì기ë¯ë¡, ëëë¡ íê²½ë³ìë¡ë¶í° ë°ìê²ì´ íì¤íê°ë¥¼ íì¸í íìê° ìì ëë ìë¤. ì´ë¥¼ ìí´ <function>getenv</function> í¨ì를 ì¬ì©íë¤. íê²½ ë³ì를 ì¤ì í기 ìí´ìë <function>putenv</function> í¨ì를 ì¬ì©íë¤. </para> </sect2> <sect2 id="language.variables.external.dot-in-names"> <title>ì¸ë¶ ë³ìëª ì ìë '.' (Dots in incoming variable names)</title> <para> ì¼ë°ì ì¼ë¡ PHPë ë³ì를 ì¤í¬ë¦½í¸ë¡ ê°ì ¸ì¬ ë ë³ìëª ì ë°ê¾¸ì§ ìëë¤. ê·¸ë¬ë, PHPì ë³ìëª ìë '.' (ì )ì ì¬ì©í ì ìë¤. ë¤ìê³¼ ê°ì ê²½ì°ë¥¼ ë³´ì. : <programlisting role="php"> $varname.ext; /* invalid variable name */ </programlisting> ìì ê²½ì° PHP íìë <varname>$varname</varname>ì´ë¼ë ë³ìì, ì°ê²° ì°ì°ì, 'ext'(ë°ì´íê° ìë ê²½ì° ê·¸ê²ì´ ì´ë¤ ìë ¤ì§ í¤ë ìì½ì´ê° ìëë©´ 문ìì´ë¡ ì·¨ê¸ëë¤.)ë¡ í´ìíë¤. ì´ê²ì ì°ë¦¬ê° ìíë ê²°ê³¼ê° ìëë¤. </para> <para> ìì ê°ì ì´ì ë¡ PHPë ì¸ë¶ìì ë¶ë¬ë¤ì¸ ë³ìì ì´ë¦ì '.'ì´ ìì¼ë©´ '_'(ë°ì¤)ë¡ ë°ê¾¸ì´ ì½ì´ë¤ì¸ë¤. </para> </sect2> <sect2 id="language.variables.determining-type-of"> <title>ë³ìì Type íë¨ (Determining variable types)</title> <para> PHPë ë³ìì typeì ììì ì íê³ (ì¼ë°ì ì¼ë¡) íìí ê²½ì°ìë ê·¸ typeì ë°ê¾¸ë¯ë¡, í¹ì ìì ì ê·¸ ë³ì ì´ë¤ typeì¸ì§ë ì½ê² ì ì ìë¤. PHPë ë³ìì typeì ìì보기 ìí´ ì¬ë¬ê°ì í¨ì를 ê°ì§ê³ ìë¤. <function>gettype</function>, <function>is_long</function>, <function>is_double</function>, <function>is_string</function>, <function>is_array</function>, <function>is_object</function> ê° ê·¸ê²ë¤ì´ë¤. </para> </sect2> </sect1> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: -->