cvs: phpdoc /kr/language variables.xml

From: 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 (&amp;) 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"> &lt;?php $foo = 'Bob'; // Assign the value 'Bob' to $foo $bar = &amp;$foo; // Reference $foo via $bar. $bar = "My name is $bar"; // Alter $bar... echo $foo; // $foo is altered too. echo $bar; ?&gt; </programlisting> </informalexample> </para> <para> One important thing to note is that only named variables may be assigned by reference. <informalexample> <programlisting role="php"> &lt;?php $foo = 25; $bar = &amp;$foo; // This is a valid assignment. $bar = &amp;(24 * 7); // Invalid; references an unnamed expression. function test() { return 25; } $bar = &amp;test(); // Invalid. ?&gt; </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> 위의 스크립트는 &quot;3&quot;을 출력할 것이다. 함수 내에서 <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 &quot;0&quot;. 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 &lt; 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"> &lt;form action="foo.php" method="post"> Name: &lt;input type="text" name="username">&lt;br> &lt;input type="submit"> &lt;/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"> &lt;form action="array.php" method="post"> Name: &lt;input type="text" name="personal[name]">&lt;br> Email: &lt;input type="text" name="personal[email]">&lt;br> Beer: &lt;br> &lt;select multiple name="beer[]"> &lt;option value="warthog">Warthog &lt;option value="guinness">Guinness &lt;option value="stuttgarter">Stuttgarter Schwabenbr&auml;u &lt;/select> &lt;input type="submit"> &lt;/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"> &lt;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: -->
« previous php.doc (#969333499) next »