text
stringlengths 1
254
| output
stringlengths 2
255
|
---|---|
The PHP community is encouraging all to not rely on this directive as it' s preferred to assume it's off and code accordingly.
|
PHPã§ã¯ãã©ãŒã 倿°ã®ã³ã³ããã¹ãå
ã§é
åã䜿çšå¯èœã§ã( FAQã®é¢é£ç®æ ãåç
§ããŠãã ãã)ã äŸãã°ãé¢é£ãã倿°ãã°ã«ãŒãåããããselect inputã§è€æ°ã®å€ã ååŸãããšãã£ãããšãå¯èœã§ãããã©ãŒã ãåãã¹ã¯ãªããã«æçš¿ãã æçš¿ããããŒã¿ã衚瀺ããäŸã瀺ããŸãã
|
If turned on, value (It's "PHP !") will automagically become (It\'s \"PHP!\").
|
äŸ 8-3ããè€éãªãã©ãŒã 倿°
|
PHP also understands arrays in the context of form variables (see the related faq).
|
PHP 3ã§ã¯ãé
å倿°ã¯1次å
é
åã«éå®ãããŠããŸãããPHP 4ã§ã¯ãã® ãããªå¶çŽã¯ãããŸããã
|
For example, let 's post a form to itself and upon submission display the data:
|
ãã©ãŒã ãæçš¿ããéãæ¬¡ã®ã¿ã°ã®ããã«æšæºã®æçš¿ãã¿ã³ã®ä»£ããã« ç»åã䜿çšããããšãã§ããŸãã
|
In PHP 3, the array form variable usage is limited to single-dimensional arrays.
|
ç»åã®ã©ãããã¯ãªãã¯ãããå Žåãäºã€ã®å€æ° sub_x ããã³ sub_y ãä»ãå ããããŠãã®ãã©ãŒã ã¯ãµãŒããŒã«è»¢éãããŸãããããã®å€ æ°ã¯ããŠãŒã¶ãŒããã®ç»åãã¯ãªãã¯ãã座æšã瀺ããŠããŸããçµéšã® ãã人ã¯ããã©ãŠã¶ã«ããéããã倿°ã®ååã«ãããŠã¢ã³ããŒã¹ã³ã¢ ãããªãªãã«ãªã£ãŠããŸã£ãŠããããšãå¿é
ãããããããŸããã ããããPHP ã¯ããªãªããã¢ã³ããŒã¹ã³ã¢ã«èªåçã«å€æããŸãã
|
See the setcookie() manual page for more details and examples.
|
åäžã®Cookieã«è€æ°ã®å€ã代å
¥ãããå Žåã¯ãé
åãšã㊠代å
¥ããããšãå¯èœã§ãã以äžã«äŸã瀺ããŸãã
|
That will create two seperate cookies although MyCookie will now be a single array in your script.
|
äžèšã¹ã¯ãªããã«ãããŠã¯ã2ã€ã®ç°ãªãCookieãçæãããŸããã ãã®å Žåãã¹ã¯ãªããã§ã¯MyCookieãšããåäžã®é
åã«ãªããŸãã äžã€ã®Cookieã«è€æ°ã®å€ãèšå®ãããå Žåãæåã®å€ã« serialize() ãŸã㯠explode() ãçšããããšãèããŠãã ããã
|
Note that a cookie will replace a previous cookie by the same name in your browser unless the path or domain is different.
|
Cookieã¯ããã¹ãŸãã¯ãã¡ã€ã³ãç°ãªããªãéãã 以åã®ã¯ãããŒããã©ãŠã¶äžã®åãååã®å€æ°ã«çœ®ãæããããšã« 泚æããŠãã ããã ããŠãè²·ãç©ãã(Shopping Cart) ããã°ã©ã ã®å Žåãã«ãŠã³ã¿ãä¿æãã åãæž¡ããããšæããããããŸããã ããã¯ã次ã®ããã«ãªããŸãã
|
?php $count++; setcookie("count", $count, time()+3600); setcookie("Cart[$count]", $item, time()+3600);?
|
äŸ 8-4 setcookie() ã®äŸ
|
However, it should be noted that the dot (period, full stop) is not a valid character in a PHP variable name.
|
éåžžãPHP ã¯ã¹ã¯ãªããã«æž¡ããã倿°ã®ååã倿ŽããŸããããããã ããã(ããªãªããçµæ¢ç¬Š)ã¯PHPã®å€æ°åã§æå¹ãªæåã§ã¯ãªããšããã ãšã«æ³šæããå¿
èŠããããŸããæ¬¡ã®äŸãèŠãŠã¿ãŸãããã
|
For this reason, it is important to note that PHP will automatically replace any dots in incoming variable names with underscores.
|
éèŠãªããšãèšè¿°ããŠãããšããã®ãããå€éšå€æ°ã«å«ãŸãããããã PHP ã¯èªåçã«ã¢ã³ããŒã¹ã³ã¢ã«å€æããŸãã
|
PHP includes several functions which find out what type a variable is, such as: gettype(), is_array(), is_float(), is_int(), is_object(), and is_string().
|
PHPã¯ã倿°ã®åãå®çŸ©ããå¿
èŠã«å¿ããŠå€æããŸãããã®ãããããå€ æ°ã®åãããæç¹ã§åžžã«æããã§ããããã§ã¯ãããŸãããPHPã¯ã倿° ã®åã調ã¹ãè€æ°ã®é¢æ°ããµããŒãããŠããŸãããããã¯ã gettype(), is_array(), is_float(), is_int(), is_object(), is_string() ã§ãã å ã®ç« ãåç
§äžããã
|
As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
|
PHP ã®å€æ°ã¯ãã«èšå·ã®åŸã«å€æ°åãç¶ã圢åŒã§è¡šãããŸãã 倿°åã¯å€§æåå°æåãåºå¥ããŸãã
|
?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Àyte = 'mansikka'; / / valid; 'À 'is ASCII 228.?
|
倿°åã¯ãPHPã®ä»ã®ã©ãã«ãšåãã«ãŒã«ã«åŸããŸãã æå¹ãªå€æ°åã¯æåãŸãã¯ã¢ã³ããŒã¹ã³ã¢ããå§ãŸããä»»æã®æ°ã®æåã æ°åãã¢ã³ããŒã¹ã³ã¢ãç¶ããŸããæ£èŠè¡šçŸã«ããã°ãããã¯æ¬¡ã® ããã«è¡šçŸããããšãã§ããŸãã '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
|
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.
|
泚æ ããã§èšããšããã®æåãšã¯a-zãA-Zã127ãã255ãŸã§ (0x7f-0xff)ã®ã¢ã¹ããŒæåãæå³ããŸãã
|
To assign by reference, simply prepend an ampersand () to the beginning of the variable which is being assigned (the source variable).
|
PHP 3ã§ã¯ã倿°ã¯åžžã«ãã®å€ã«ãã代å
¥ãããŠããŸããã ããã¯ãã€ãŸãããã倿°ã«ããåŒã代å
¥ããéãå
ã®åŒã® å€å
šäœãã³ããŒãããåŽã®å€æ°ã«ã³ããŒããããšããããšã§ãã ããã¯ãäŸãã°ããã倿°ã®å€ãä»ã®å€æ°ã«ä»£å
¥ããåŸã§ã ãããã®å€æ°ã®1ã€ã倿ŽããŠãä»ã®å€æ°ã«ã¯åœ±é¿ãäžããªããšãã ããšãæå³ããŸãããã®çš®ã®ä»£å
¥ã«é¢ããããè©³çŽ°ãªæ
å ±ã«ã€ããŠã¯ã åŒ ãåç
§äžããã
|
?php $foo = 'Bob'; / / Assign the value'Bob' to $foo $bar = $foo; / / Reference $foo via $bar. $bar = "My name is $bar"; / / Alter $bar... echo $bar; echo $foo; / / $foo is altered too.?
|
PHP 4 ã¯å€æ°ã«å€ã®ä»£å
¥ãè¡ãå¥ã®æ¹æ³ãæäŸããŸããããã¯ã åç
§ã«ãã代å
¥ ã§ãã ãã®å Žåãæ°èŠã®å€æ°ã¯å
ã®å€æ°ãåç
§ããã ãã§ãã (èšãããããšãå
ã®å€æ°ã®"ãšã€ãªã¢ã¹ãäœã"ãŸãã¯å
ã®å€æ°ã"æã") æ°èŠã®å€æ°ãžã®ä»£å
¥ã¯ãå
ã®å€æ°ã«åœ±é¿ãããã®éãåæ§ãšãªããŸãã ãã®ææ³ã§ã¯ã³ããŒã¯è¡ãããªãããã代å
¥ã¯ããéããã«è¡ãããŸãã ããããé床ã®åäžãäœæã§ããã®ã¯ãéãã«ãŒãã倧ããªé
åãŸã㯠ãªããžã§ã¯ããå²ãä»ããå Žåã«éããããã®ãšæãããŸãã
|
?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.?
|
åç
§ã«ãã代å
¥ãè¡ãã«ã¯ã代å
¥ãã倿°(ãœãŒã¹å€æ°)ã®å
é ã« ã¢ã³ããµã³ããå ããŸããããšãã°ã次ã®ç°¡åãªã³ãŒã㯠'My name is Bob'ãäºåºŠåºåããŸãã
|
For example, in Perl 'Z'+1 turns into'AA', while in C'Z'+1 turns into '[' {ord('Z') == 90, ord('[') == 91).
|
泚æãã¹ãéèŠãªç¹ãšããŠãååã®ãã倿°ã®ã¿ãåç
§ã«ãã代å
¥ã§ãã ãšããããšããããŸãã
|
Many of these variables, however, cannot be fully documented as they are dependent upon which server is running, the version and setup of the server, and other factors.
|
PHPã¯ãå®è¡ããå
šãŠã®ã¹ã¯ãªããã«å®çŸ©æžã¿ã®å€ãã®å€æ°ã æäŸããŸãããããããããã®å€æ°ã®å€ãã¯ã å®è¡ãããµãŒããŒã®çš®é¡ããµãŒããŒã®ããŒãžã§ã³ããã³èšå®ã ãã®ä»ã®èŠçŽ ã«äŸåããŠãããå®å
šã«èšè¿°ããããšã¯ã§ããŸããã ãããã®å€æ°ã®ããã€ãã¯ãPHPã ã³ãã³ãã©ã€ã³ ã§å®è¡ããå Žåã«ã¯å©çšã§ããŸããã ãããã®å€æ°ã®äžèЧã«ã€ããŠã¯ã äºçŽæžã¿ã®å®çŸ©æžã¿ã®å€æ° ã®ã»ã¯ã·ã§ã³ãåç
§ããŠãã ããã
|
Using the available PHP Reserved Predefined Variables, like the superglobal arrays, is preferred.
|
ãã®å€æŽã«é¢ããæ
å ±ã«ã€ããŠã¯ã register_globals ã«é¢ããèšå® ãšã³ããªãã»ãã¥ãªãã£ã«é¢ããç« ã® register_globalsã®äœ¿çš ã ãŸãã 4.1.0 ããã³ 4.2.0 ã® Release Announcementsãåç
§ããŠäžããã
|
These new arrays are rather special in that they are automatically global--i.e., automatically available in every scope.
|
ã¹ãŒããŒã°ããŒãã« é
å ã®ãããªPHPã®äºçŽæžã¿ã®å®çŸ©æžã¿å€æ°ã䜿çšããããšã æšå¥šãããŸãã
|
If certain variables in variables_order are not set, their appropriate PHP predefined arrays are also left empty.
|
variables_order ã« ãã倿°ãèšå®ãããŠããªãå Žåããããã«å¯Ÿå¿ããPHPã®å®çŸ©æžã¿ 倿°ã空ã®ãŸãŸãšãªããŸãã
|
PHP Superglobals
|
PHP ã¹ãŒããŒã°ããŒãã«
|
The keys of this array are the names of the global variables. $GLOBALS has existed since PHP 3.
|
ã¹ã¯ãªããã®ã°ããŒãã«ã¹ã³ãŒãã®äžã§çŸåšå©çšå¯èœãªå
šãŠã® 倿°ãžã®ãªãã¡ã¬ã³ã¹ãå«ã¿ãŸãããã®é
åã®ããŒã¯ãã°ããŒãã« å€æ°ã®ååã§ãã $GLOBALS ã¯ãPHP 3以éååšããŸãã
|
Analogous to the old $HTTP_SERVER_VARS array (which is still available, but deprecated).
|
WebãµãŒããŒãŸãã¯ã«ã¬ã³ãã®ã¹ã¯ãªããã®å®è¡ç°å¢ã«çŽæ¥é¢ä¿ãã ãã®ã«ããèšå®ããã倿°ã以åã®(ãŸã å©çšå¯èœã§ãããæšå¥š ãããŸãã) $HTTP_SERVER_VARS é
åã« é¡äŒŒã®ãã®ã§ãã
|
Analogous to the old $HTTP_GET_VARS array (which is still available, but deprecated).
|
HTTP GETã«ããã¹ã¯ãªããã«å
¥åããã倿°ã以åã® (ãŸã å©çšå¯èœã§ãããæšå¥šãããŸãã) $HTTP_GET_VARS é
åã«é¡äŒŒã®ãã®ã§ãã
|
Analogous to the old $HTTP_POST_VARS array (which is still available, but deprecated).
|
HTTP POSTã«ããã¹ã¯ãªããã«å
¥åããã倿°ã以åã® (ãŸã å©çšå¯èœã§ãããæšå¥šãããŸãã) $HTTP_POST_VARS é
åã«é¡äŒŒã®ãã®ã§ãã
|
Analogous to the old $HTTP_COOKIE_VARS array (which is still available, but deprecated).
|
HTTP Cookieã«ããã¹ã¯ãªããã«å
¥åããã倿°ã以åã® (ãŸã å©çšå¯èœã§ãããæšå¥šãããŸãã) $HTTP_COOKIE_VARS é
åã«é¡äŒŒã®ãã®ã§ãã
|
Analogous to the old $HTTP_POST_FILES array (which is still available, but deprecated).
|
HTTP POSTãã¡ã€ã«ã¢ããããŒãã«ããã¹ã¯ãªããã«æž¡ããã倿°ã 以åã® $HTTP_POST_FILES é
å(ãŸã å©çšå¯èœã§ããã æšå¥šãããŸãã)ãšé¡äŒŒããŠããŸãã詳现ã«ã€ããŠã¯ã POSTã¡ãœãã ã®ã¢ããããŒã ãåç
§ããŠäžããã
|
Analogous to the old $HTTP_ENV_VARS array (which is still available, but deprecated).
|
ç°å¢ã«ããã¹ã¯ãªããã«æå®ããã倿°ã 以åã® $HTTP_ENV_VARS é
å(ãŸã å©çšå¯èœã§ããã æšå¥šãããŸãã)ãšé¡äŒŒããŠããŸãã
|
The presence and order of variable inclusion in this array is defined according to the variables_order configuration directive.
|
ãŠãŒã¶å
¥åæ©æ§ã«ããã¹ã¯ãªããã«å
¥åãããå
šãŠã®å€æ°ã§ã ãã®ãããä¿¡é Œããããšãã§ããŸããããã®é
åã«å«ãŸãã 倿°ã®ååšãšé çªã¯ãèšå®ãã£ã¬ã¯ãã£ã variables_order ã«åºã¥ãå®çŸ©ãããŸãããã®é
åã¯ã4.1.0ããåã®ããŒãžã§ã³ã®PHP ã«ã¯çŽæ¥é¡äŒŒãããã®ã¯ãããŸããã import_request_variables() ãåç
§ããŠãã ããã
|
Variables which are currently registered to a script 's session.
|
泚æ ã³ãã³ãã©ã€ã³ ã§å®è¡ããŠããå Žåããã®å€æ°ã«ã¯ã argv ããã³ argc ãšã³ã㪠ã¯å«ãŸããŸããããããã¯ã $_SERVER é
åã«ã¯ ååšããŸãã
|
See the Session handling functions section for more information.
|
ã¹ã¯ãªããã®ã»ãã·ã§ã³ã«çŸåšç»é²ãããŠãã倿°ã 以åã® $HTTP_SESSION_VARS é
å(ãŸã å©çšå¯èœã§ããã æšå¥šãããŸãã)ãšé¡äŒŒããŠããŸãã詳现ã«ã€ããŠã¯ã ã»ãã·ã§ã³åŠç颿° ãåç
§ãã ããã
|
However, within user-defined functions a local function scope is introduced.
|
倿°ã®ã¹ã³ãŒãã¯ããã®å€æ°ãå®çŸ©ãããã³ã³ããã¹ãã§ããã»ãšãã©ã® PHP 倿°ã¯ãã¹ã³ãŒãã1ã€ã ãæããŠããŸãããã®ã¹ã³ãŒãã®ç¯å²ã¯ã includeãrequireã«ããèªã¿ããŸãããã¡ã€ã«ãå«ã¿ãŸããäŸãã°ã
|
This script will not produce any output because the echo statement refers to a local version of the $a variable, and it has not been assigned a value within this scope.
|
ãã®äŸã§ã倿° $a ã¯ã€ã³ã¯ã«ãŒãããã b.inc ã¹ã¯ãªããã®äžã§ãå©çšå¯èœã§ãããããã ãŠãŒã¶ãŒå®çŸ©ã®é¢æ°ã®äžã§ã¯å€æ°ã®æå¹ç¯å²ã¯ããŒã«ã«é¢æ°ã®äžãšãªã㟠ãã颿°ã®äžã§äœ¿çšããã倿°ã¯ããã©ã«ãã§æå¹ç¯å²ã颿°å
éšã«å¶é ãããŸããäŸãã°ã
|
There is no limit to the number of global variables that can be manipulated by a function.
|
äžã®ã¹ã¯ãªããã¯ã"3" ãåºåããŸãã颿°ã®å
éšã§ $a ã $b ãã°ããŒãã«å®£èšãè¡ãããšã«ãããäž¡å€æ°ãžã®åç
§ã¯ãã°ããŒãã«å€æ° ã®æ¹ãåç
§ããããšã«ãªããŸãããã颿°ã«ããæäœã§ããã°ããŒãã«å€ æ°ã®æ°ã¯ç¡å¶éã§ãã
|
The $GLOBALS array is an associative array with the name of the global variable being the key and the contents of that variable being the value of the array element.
|
ã°ããŒãã«ã¹ã³ãŒããã倿°ãã¢ã¯ã»ã¹ãã2çªç®ã®æ¹æ³ã¯ãPHPãå®çŸ©ã ãé
å $GLOBALS ã䜿çšããããšã§ããå
ã®äŸã¯ã次 ã®ããã«æžãæããããšãã§ããŸãã
|
Superglobals are available / / as of PHP 4.1.0 print $_POST[ 'name'];}?
|
é
å $GLOBALS ã¯é£æ³é
åã§ãããã°ããŒãã«å€æ°ã® ååãããŒããã®å€æ°ã®å
容ãé
åèŠçŽ ã®å€ãšãªã£ãŠããŸãã $GLOBALS 㯠ã¹ãŒããŒã°ããŒãã« ã§ããããã $GLOBALS ã¯å
šãŠã®ã¹ã³ãŒãã«ååšããŸãã 以äžã«ã¹ãŒããŒã°ããŒãã«ã®å¹æã瀺ãäŸã瀺ããŸãã
|
A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope.
|
倿°ã®ã¹ã³ãŒãã«é¢ããå¥ã®éèŠãªæ©èœã¯ã éç (static) 倿°ã§ããéç倿°ã¯ããŒã«ã«é¢æ°ã¹ã³ãŒãã®ã¿ã« ååšããŸãããããã°ã©ã å®è¡ããã®ã¹ã³ãŒãã®å€ã§è¡ãããããã«ãªã£ ãŠããã®å€ã倱ããªããŸãããæ¬¡ã®äŸãèŠãŠãã ããã
|
To make a useful counting function which will not lose track of the current count, the $a variable is declared static:
|
ãã®é¢æ°ã¯ãã³ãŒã«ããã床㫠$a ã 0 ã«ã»ãããã"0" ãåºåããã®ã§ã»ãšã ã©åœ¹ã«ãã¡ãŸããã倿°ã1å¢ãã $a++ ã¯ã颿°ããå€ã«åºããšå€æ° $a ãæ¶ããŠããŸãããã«ç®çãéæããŸãããçŸåš ã®ã«ãŠã³ãã®è¿œè·¡ãã§ããããã«ã«ãŠã³ã颿°ã䜿çšã§ããããã«ããã ãã«ã¯ã倿° $a ãstaticãšããŠå®£èšããŸãã
|
?php function Test() {static $count = 0; $count++; echo $count; if ($count 10) {Test ();} $count--;}?
|
ãããããšãTest() 颿°ãã³ãŒã«ããã床㫠$a ã®å€ ãåºåãããã®å€ãå¢å ãããŸãã
|
For example, a true global variable imported inside a function scope with the global statement actually creates a reference to the global variable.
|
static倿°ã¯ãååž°é¢æ°ãå®çŸãã1ã€ã®ææ®µãšããŠã䜿çšãããŸããååž° 颿°ã¯ãèªåèªèº«ãã³ãŒã«ãã颿°ã§ããååž°é¢æ°ãæžããšãã«ã¯ãç¡é ã«ååž°ãè¡ãå¯èœæ§ããããããæ³šæããå¿
èŠããããŸããé©åœãªæ¹æ³ã« ããååž°ã確å®ã«çµäºãããå¿
èŠããããŸããæ¬¡ã®ç°¡åãªé¢æ°ã¯ãäžæ¢ã ãã¿ã€ãã³ã°ãç¥ãããã«static倿° $count ãçšããŠã 10 åãŸã§ååž°ãè¡ããŸãã
|
?php function test_global_ref() {global $obj; $obj = new stdclass;} function test_global_noref() {global $obj; $obj = new stdclass;} test_global_ref(); var_dump($obj); test_global_noref(); var_dump($obj);?
|
PHP4 ãé§åããZend Engine 1ã§ã¯ã ãªãã¡ã¬ã³ã¹å€æ°ã®ä¿®æ£å static ããã³ global ãå®è£
ããŠããŸãã äŸãã°ã颿°ã¹ã³ãŒãå
ã« global åœä»€ã«ããå®éã«ã€ã³ããŒããããçã®ã°ããŒãã«å€æ°ã¯ã å®éã«ã°ããŒãã«å€æ°ãžã®ãªãã¡ã¬ã³ã¹ãäœæããŸãã ããã«ããã以äžã®äŸã瀺ãããã«äºæž¬ã§ããªãåäœãåŒãèµ·ããå¯èœæ§ ããããŸãã
|
NULL object( stdClass)(0) {}
|
ãã®äŸãå®è¡ãããšä»¥äžã®åºåãçµæãšããŠè¡šç€ºãããŸãã
|
References are not stored statically:
|
é¡äŒŒã®åäœã static åœä»€ã«ãé©çšãããŸãã ãªãã¡ã¬ã³ã¹ã¯éçã«ä¿åããããšãã§ããŸããã
|
Static object:
|
ãã®äŸãå®è¡ãããšä»¥äžã®åºåãšãªããŸãã
|
This example demonstrates that when assigning a reference to a static variable, it' s not remembered when you call the get_instance_ref() function a second time.
|
ãã®äŸã¯ãstatic倿°ã«ãªãã¡ã¬ã³ã¹ã代å
¥ããæã« get_instance_ref() 颿°ã2åç®ã« ã³ãŒã«ããéã«ä¿æãããŠããªãããšã瀺ããŠããŸãã
|
That is, a variable name which can be set and used dynamically.
|
倿°åãå¯å€ã«ã§ãããšäŸ¿å©ãªããšãæã
ãããŸããå¯å€å€æ°ã§ã¯ã倿° åãåçã«ã»ããã䜿çšã§ããŸããéåžžã®å€æ°ã¯ã次ã®ãããªåœä»€ã§ã»ã ãããŸãã
|
In the above example, hello, can be used as the name of a variable by using two dollar signs. i.e.
|
å¯å€å€æ°ã¯ã倿°ã®å€ããšãã倿°ã®ååãšããŠæ±ããŸããäžã®äŸã§ã¯ã hello ã¯ããã«èšå·ãäºã€äœ¿çšããããšã«ããã 倿°ã®ååãšããŠäœ¿çšããããšãã§ããŸããã€ãŸãã
|
Therefore, this statement:
|
ãããŸã§ã§ãäºã€ã®å€æ°ãå®çŸ©ãããPHP ã·ã³ãã«ããªãŒã«å®çŸ©ãããŠã ãŸãããããã¯ã"hello" ãå€ãšãã $a ãš "world" ãå€ãšãã $hello ã§ããããã§ã次ã®åœä»€
|
?php echo "$a $hello";?
|
ã®åºåã¯ã次ã®åœä»€ãšå
šãåããšãªããŸãã
|
In order to use variable variables with arrays, you have to resolve an ambiguity problem.
|
ããªãã¡ãäž¡æ¹å
±ã hello world ãåº åããŸãã
|
The syntax for resolving this ambiguity is: ${$a[1]} for the first case and ${$a}[1] for the second.
|
å¯å€å€æ°ãé
åã§äœ¿çšããéã«ã¯ãææ§ãã®åé¡ã解決ããå¿
èŠããã㟠ããã€ãŸãã $$a[1] ãšæžããå Žåã $a[1] ã倿°ãšããŠäœ¿çšãããã®ãã $$a ã倿°ãšã [1] ã倿°ã®æ·»ãåãšãããã®ããã ããŒãµãç¥ãå¿
èŠãããã®ã§ãããã®ææ§ãã解決ããã«ã¯ãåè
ã§ã¯ ${$a[1]} ãšããåŸè
ã§ã¯ ${$a}[1] ãšããæ§æãçšããŸãã
|
If you are looking for a way to handle availability of superglobals and the old HTTP_*_VARS, you might want to try referencing them.
|
å¯å€å€æ°ã¯ãPHPã® ã¹ãŒããŒã°ããŒãã«é
å ã§äœ¿çšããããšãã§ããªãããšã«æ³šæã㊠äžãããããã¯ã ${$_GET} ã®ãããªããšãè¡ãªãããšã ã§ããªãããšãæå³ããŸãã ã¹ãŒããŒã°ããŒãã«ããã³ HTTP_*_VARS ã® å©çšå¯èœæ§ãåŠçããææ®µãæ¢ããŠããå Žåããããã® ãªãã¡ã¬ã³ã¹ãäœæ ãã ããšã詊ããŠã¿ãŠäžããã
|
The global configuration file, php3.ini, has changed its name to php.ini.
|
ã°ããŒãã«èšå®ãã¡ã€ã« php3.ini ã¯ãååã php.ini ã«å€æŽãšãªããŸããã
|
The MIME types recognized by the PHP module have changed.
|
Apacheèšå®ãã¡ã€ã«ã®å Žåã倿Žç¹ã¯ããå€ããªã£ãŠããŸããPHPã¢ãžã¥ãŒ ã«ã«ããèªèãããMIMEåã倿ŽãšãªããŸããã
|
You can make your configuration files work with both versions of PHP (depending on which one is currently compiled into the server), using the following syntax:
|
以äžã®æ§æã䜿çšããããšã«ããã(ãµãŒãã«çµã¿èŸŒãŸããŠããããŒãžã§ ã³ã«åºã¥ã)äž¡æ¹ã®ããŒãžã§ã³ã§åäœããèšå®ãã¡ã€ã«ãäœæããããšã å¯èœã§ãã
|
AddType application / x-httpd-php3 .php3 AddType application / x-httpd-php3-source .php3s AddType application / x-httpd-php .php AddType application / x-httpd-php-source .phps
|
å ããŠãApacheçšã®PHPãã£ã¬ã¯ãã£ãã倿Žãšãªã£ãŠããŸãã
|
Starting with PHP 4.0, there are only four Apache directives that relate to PHP:
|
PHP 4以éãPHPã«é¢é£ããApacheãã£ã¬ã¯ãã£ãã¯ä»¥äžã®4çš®é¡ã®ã¿ãš ãªã£ãŠããŸãã
|
php_value [PHP directive name] [value] php_flag [PHP directive name] [On_BAR_Off] php_admin_value [PHP directive name] [value] php_admin_flag [PHP directive name] [On_BAR_Off]
|
Adminã®å€ãšãã以å€ã®å€ã«ã¯æ¬¡ã®2ã€ã®éãããããŸãã
|
Admin values (or flags) can only appear in the server-wide apache configuration files (e.g., httpd.conf).
|
Admin ã®å€(ãŸãã¯ãã©ã°)ã¯ããµãŒãå
šäœã®Apacheèšå®ãã¡ã€ã«(ã㪠ãã¡httpd.conf)ã§ã®ã¿èšå®å¯èœã§ãã
|
In contrast, Admin values can modify the value of any PHP directive.
|
éåžžã®å€(ãŸãã¯ãã©ã°)ã¯ã»ãŒãã¢ãŒãã®ãããªããçš®ã®PHPãã£ã¬ã¯ ãã£ããå¶åŸ¡ã§ããŸãã(ã»ãŒãã¢ãŒãã®èšå®ã.htaccessã§äžæžãã§ ãããšããããã»ãŒãã¢ãŒãã®ç®çã¯éæãããªããªããŸã)ãéã« Adminå€ã§ã¯å
šãŠã®PHPãã£ã¬ã¯ãã£ãã®å€ãä¿®æŽå¯èœã§ãã
|
These scripts do NOT convert the mime type lines!
|
ç§»è¡ã®éçšããã容æã«ããããã«ãPHP 4ã«ã¯Apacheèšå®åœä»€ãš. htaccessãã¡ã€ã«ãPHP 3ãšPHP 4ã®äž¡æ¹ã§åäœããããã«å€æããã¹ ã¯ãªããããã³ãã«ãããŠããŸãããããã®ã¹ã¯ãªããã¯ãMIMEåã®è¡ã 倿ããŸããããããã¯èªåã§å€æŽãè¡ãå¿
èŠããããŸãã
|
To convert your Apache configuration files, run the apconf-conv.sh script (available in the scripts / apache / directory).
|
Apacheèšå®ãã¡ã€ã«ã倿ããããã«ã(scripts/apache/ãã£ã¬ã¯ããªã« ãã)apconf-conv.sh ã¹ã¯ãªãããå®è¡ããŠäžããã äŸãã°ã
|
~ / php4 / scripts / apache:#. / apconf-conv.sh / usr / local / apache / conf / httpd.conf
|
å
ã®èšå®ãã¡ã€ã«ã¯ãhttpd.conf.origã«ä¿åãããŸãã
|
To convert your .htaccess files, run the aphtaccess-conv.sh script (available in the scripts / apache / directory as well):
|
.htaccess ãã¡ã€ã«ã倿ããã«ã¯ã(åããscripts/apache/ãã£ã¬ã¯ã ãªã«ãã)aphtaccess-conv.sh ã¹ã¯ãªãããå®è¡ããŠäžããã
|
Likewise, your old .htaccess files will be saved with an .orig prefix.
|
åæ§ã«å€ã.htaccessãã¡ã€ã«ã«ã¯.origãä»å ãããŠä¿åãããŸãã
|
Prev
|
ãã®å€æã¹ã¯ãªããã¯ãawkãã€ã³ã¹ããŒã«ãããŠããããšãå¿
èŠãšããŸãã
|
PHP 4 breaks with this habit and creates the cookie header lines in exactly the same order as you set the cookies in the code.
|
PHP 3ã¯ãã³ãŒãäžã® setcookie() ã®ã³ãŒã«ãšã¯é ã®é çªã§ã¯ãããŒãèšå®ãããšãã奜ãŸãããªãåäœãããŠããŸããã PHP 4ã¯ãã®åäœã倿Žããã³ãŒãã§ã¯ãããŒãèšå®ããã®ãšåãé çª ã§æ£ããã¯ãããŒãèšå®ãããããè¡ãçæããŸãã
|
Prev
|
ããã«ããããã€ãã®æ¢åã®ã³ãŒããåäœããªããªãå¯èœæ§ããããŸããã åŸæ¥ã®åäœã¯çè§£ãã«ãããå°æ¥çãªæŽãªãåé¡ãé²ãããã«å€æŽæãŸã ãŠããŸããã
|
A String containing only the character '0' (zero) is now considered empty while it wasn't in PHP 3.
|
æããæãåäœäžã®åé¡ã®ãã倿Žã¯ã empty() ã®å äœã«é¢ãããã®ã§ããããæå '0' (ãŒã)ã®ã¿ãå«ãæååã¯ãPHP 3 ãšã¯ç°ãªã空æååãšã¿ãªãããããã«ãªããŸããã
|
But on the other hand it might break your code in a rather subtle way, leading to misbehavior that is hard to track down if you do not know about what to look for.
|
æ°å€ã®å
¥åãèŠæ±ãããå Žåã§ãå
šãŠã®inputãã£ãŒã«ãã¯æååãè¿ãã PHPã¯èªåçã«å倿ãè¡ãæ©èœãæããŠããããããã®åäœã®å€æŽã¯ã Webã¢ããªã±ãŒã·ã§ã³ã«ãããŠææçŸ©ãªãã®ã§ããããããäžæ¹ãã³ãŒã ã®æ£åžžåäœãé»å®³ããå¯èœæ§ããããåäœã®å
容ãç¥ããªãå Žåã«ã¯ã åå ã远æ±ããããåäœã®äžåãçããå¯èœæ§ããããŸãã
|
Usual values where 15 for reporting all errors and warnings or 7 for reporting everything but simple notice messages reporting bad style and things like that.
|
PHP 3ã§ã¯ããšã©ãŒåºåã¬ãã«ã¯ç°ãªã£ããšã©ãŒã¬ãã«ãæå³ããæ° ãåèšããåçŽãªæ°å€ã§è¡šãããŠããŸããããã䜿çšãããã®ã¯ãå
šãŠ ã®ãšã©ãŒãšèŠåãåºåãã15ãšå¥œãŸãããªã圢åŒãäºé
ãéç¥ããã¡ã ã»ãŒãžä»¥å€ã®å
šãŠãåºåãã7ã§ãã
|
Error reporting level should now be configured by explicitly taking away the warning levels you do not want to generate error messages by x-oring them from the symbolic constant E_ALL.
|
PHP 4ã§ã¯ãããå€ãã®ç°ãªã£ããšã©ãŒããã³èŠåã¬ãã«ãèšå®ã㊠ãããèšå®ãã¡ã€ã«ã«ãããŠæå³ããåäœãèšå®ããããã«å®æ°ã·ã³ã ã«ã䜿çšããããšãå¯èœã«ãªã£ãŠããŸãã
|
This may lead to empty documents without any feedback of what happened or where to look for the problem.
|
åŸæ¥ã®å€7ããã³15ã䜿çšããŠãšã©ãŒåºåãèšå®ããæ¹æ³ã¯ãããŒã¹ãš ã©ãŒãå«ãæ°ãã«è¿œå ããããšã©ãŒã¯ã©ã¹ã®ããã€ãã䜿çšã§ããªã㪠ããããéåžžã«æªãæ¹æ³ã§ãããã®å Žåãã¹ã¯ãªãããåäœããªãå Žå ã§ããšã©ãŒã¡ãã»ãŒãžãã©ãã«ã衚瀺ããªããããéåžžã«å¥åŠãªåäœãš ãªãããšããããŸãã
|
A lot of existing PHP 3 code uses language constructs that should be considered as very bad style as this code, while doing the intended thing now, could easily be broken by changes in other places.
|
ãã®ãããã¹ã¯ãªãããäœãåºåããã«çµäºããå Žåããšã©ãŒåºåèšå® ããŸã確èªããã¹ãã§ããçŸåšã®Zend ãšã³ãžã³ã¯ååã«å®æãããŠã ãããã®çš®ã®å¥åŠãªåäœãçºçããŸããã
|
Both PHP 3 and 4 will fall back to interpret these as strings if no keyword or constant is known by that name, but whenever a constant by that name had been defined anywhere else in the code it might break your script.
|
æ¢åã®PHP 3ã³ãŒãã®å€ãã¯ããã®ã³ãŒãã®ããã«éåžžã«æªãã¹ã¿ã€ã« ã®èšèªæ§é ã䜿çšããŠãããæå³ãããéãã«åäœããŠããå Žåã§ãã ä»ã®éšåã倿ŽãããšåäœããªããªãããšããããŸããPHP 4ã¯ãPHP 3ãåºåããªããããªå Žé¢ã§ãå€ãã®éç¥ã¡ãã»ãŒãžãåºåããŸãã E_NOTICEã¡ãã»ãŒãžããªãã«ããã°ç°¡åã«ä¿®æ£ã§ããŸãããéåžžã¯åé¡ ã®ããã³ãŒããä¿®æ£ããæ¹ãè¯ãã§ãããã
|
Another thing PHP 4 will now tell you about is the use of uninitialized variables or array elements.
|
ãã®ä»ãPHP 4ã§ã¯åæåãããŠããªã倿°ãŸãã¯é
åèŠçŽ ã䜿çšã ãŠããããšãç¥ãããããã«ãªã£ãŠããŸãã
|
It is not difficult to port extensions to PHP 4 if you have access to the original source.
|
PHP 3çšã«æãããæ¡åŒµã¢ãžã¥ãŒã«ã¯ãPHP 4ã§ã¯ãã€ããªã¬ãã«ã§ã ãœãŒã¹ã¬ãã«ã§ãåäœããŸãããå
ã®ãœãŒã¹ã«ã¢ã¯ã»ã¹å¯èœãªå Žåã PHP 4ã«ãã®æ¡åŒµã¢ãžã¥ãŒã«ãç§»æ€ããããšã¯å°é£ã§ã¯ãããŸããã å®éã®ç§»æ€ã®æé ã«ã€ããŠã®è©³çްãªèª¬æã¯ãã®æç« ã«ã¯(ãŸã )å«ãŸã㊠ããŸããã
|
This is, once again, due to the split between parsing and execution as no code has yet been executed when the parser sees the initializer.
|
éç倿°ãšã¯ã©ã¹ã¡ã³ãã®ã€ãã·ã£ã©ã€ã¶ã¯ãPHP 3ã§ã¯æå¹ãªåŒãªã ã°ãªãã§ãæå®å¯èœã§ããããPHP 4ã§ã¯ã¹ã«ã©ãŒå€ã®ã¿ãæå®å¯èœã§ ããããã¯ãåèšã®ããã«ããŒã¹ãšå®è¡ãåå²ãããŠãããããŒãµãã€ã ã·ã£ã©ã€ã¶ãåŠçããéã«ã¯ãŸã ã³ãŒãã¯å®è¡ãããŠããªãããã§ãã
|
For static variables anything but a simple static value rarely makes sense anyway.
|
ã¯ã©ã¹ã®å Žåãã¡ã³ã倿°ãåæåããéã«ã¯ã³ã³ã¹ãã©ã¯ã¿ã䜿çšãã ã¹ãã§ããéç倿°ã®å ŽåãåçŽãªã¹ã«ã©ãŒå€ä»¥å€ã®ãã®ã«æå³ãããã ãšã¯ãŸãã§ãã
|
A small number of core functions has vanished because they do not work with the new scheme of splitting parsing and execution as introduced into 4 with the Zend engine.
|
PHP 4ã¯å€ãã®æ°ããæ©èœãšæ¡åŒµãå°å
¥ããŠããŸãããåæã«ããã€ã ã®ããŒãžã§ã³3ã®é¢æ°ã¯å»æ¢ãããŠããŸããã³ã¢é¢æ°ã®ããã€ãã¯ã Zendãšã³ãžã³ã䜿çšãã4ã§å°å
¥ãããããŒãµãšå®è¡ã¢ãžã¥ãŒã«ã®åå² ãšããæ°ããªåœ¢æ
ã§ã¯åäœããªãããã廿¢ãããŠããŸããä»ã®é¢æ°ãæ¡ åŒµæ©èœå
šäœãããæ°ãã颿°ãæ¡åŒµãåãã¿ã¹ã¯ãããè¯ãããäžè¬çãª ææ³ã§è¡ãããå€ããªã£ãŠããŸããããã€ãã®é¢æ°ã¯åã«ãŸã ç§»æ€ãã㊠ããªãã ãã§ãããããã€ãã®é¢æ°ãæ¡åŒµã¯ã©ã€ã»ã³ã¹äžã®åé¡ã«ããå» æ¢ãããŠããŸãã
|
Some functions just simply haven 't been ported yet and finally some functions or extensions may be missing due to license conflicts.
|
PHP 4ã§ã¯ããŒã¹ãšå®è¡ãåå²ãããŠãããå®è¡æã«(çŸåšãZendãšã³ ãžã³ã«çµã¿èŸŒãŸããŠãã)ããŒãµã®åäœã倿Žããããšã¯ãããŒã¹ãå®è¡ åã«æ¢ã«è¡ãããŠãããããããã§ããŸããã php.ini ãã¡ã€ã«ã§é©åœãªå€ãèšå®ããããšã«ã ãããŒãµã®åäœã倿Žããããšãå¯èœã§ãã
|
So the function short_tags() no longer exists.
|
PHP 3ã®æ©èœã§PHP 4ã§ãµããŒããããŠããªãæ©èœãšããŠã¯ã ãã®ããã¥ã¢ã«ã§èšè¿°ãããŠããå®éšçãªãããã°ã€ã³ã¿ãŒãã§ãŒã¹ã® ãµããŒãããããŸããç¬ç«ããæ¬æ Œçãªãããã¬ãZendã®è£œåãšããŠãª ãªãŒã¹ãããŠããŸãã
|
Another feature of PHP 3 that is not a part of PHP 4 is the bundled debugging interface.
|
Adabas ããã³ Solid ããŒã¿ããŒã¹æ¡åŒµã¯ããã¯ãæšå¥šãããŸããã ä»åŸã¯ãunified ODBC æ¡åŒµã代ããã«äœ¿çšããŠäžããã
|
The Adabas and Solid database extensions are no more.
|
unset() ã¯ãŸã 䜿çšå¯èœã§ãããPHP 4ã§ã¯ãªãã© ã«ãšããŠå®è£
ãããããã«å€æŽãããŠããããã®ããã'çã®'颿°ãšã ãŠã¯ãã¯ãæ°ããããŠããŸããã
|
This does not have any consequences on the behavior of unset(), but testing for "unset "using function_exists() will return FALSE as it would with other language constructs that look like functions such as echo().
|
ããã¯ã unset() ã®åäœã倿Žãããã®ã§ã¯ãªãã® ã§ãçŽæ¥çãªå€æŽç¹ãããããã§ã¯ãããŸãããã function_exists() ã«ãã "unset" ã調ã¹ãå Žåã echo() ã®ãããªä»ã®äœã¬ãã«é¢æ°ãšåæ§ã« FALSE ãè¿ãããŸãã
|
Prev
|
ãã®ä»ã®ããå®éçãªå€æŽãšããŠã¯ã unset() ãé æ¥çã«ã³ãŒã«ããããšãã§ããªããªã£ããšãããã®ããããŸãããã®ã ãã $func="unset"; $func($somevar) ã¯ããåäœ ããŸããã
|
Migrating from PHP 3 to PHP 4
|
ããŒãµãšå®è¡ã¯ãäºã€ã®å®å
šã«åå²ãããã¹ãããã«ãªããŸããããã¡ã€ ã«äžã®ã³ãŒãã®å®è¡ã¯ããã¡ã€ã«å
šäœãšå¿
èŠãªãã®ãå
šãŠå®å
šã«ããŒã¹ã ãããŸã§è¡ãããŸããã
|
One of the new requirements introduced with this split is that required and included files now have to be syntactically complete.
|
ãã®åå²ã«ãã PHP 4ã§ã¯ requireãincludeã§èªã¿èŸŒãŸãããã¡ã€ã«ã æ§æçã«å®å
šã§ããããšãæ°ãã«å¿
èŠãšãªã£ãŠããŸããPHP 4ã§ã¯ãå¶åŸ¡ æ§é ã®ç°ãªãå¶åŸ¡éšããã¡ã€ã«å¢çããŸããã§é
眮ããããšã¯ã§ããŸããã ãã®ããã for ã«ãŒããŸã㯠while ã«ãŒãã if åœä»€ãŸã㯠switch ãããã¯ããããã¡ã€ã«ã§éå§ãã else ã endif, case ã break åœä»€ãå¥ã®ãã¡ã€ ã«ã«çœ®ãããšã¯ã§ããŸããã
|
That is you cannot start a for or while loop, an if statement or a switch block in one file and have the end of loop, else, endif, case or break statements in a different file.
|
ã«ãŒããŸãã¯ä»ã®å¶åŸ¡æ§é ã®äžã§è¿œå ã®ã³ãŒããèªã¿èŸŒãããšã¯ãPHP 4 ã§ã¯ãå
šãåé¡ãããŸãããå¶åŸ¡çšã®ããŒã¯ãŒãã察å¿ããæ³¢æ¬åŒ§ {...} ã ãã¯ãåãã³ã³ãã€ã«åäœ(ãã¡ã€ã«ãŸã㯠eval() ãããæåå)ã®äžã«çœ®ãå¿
èŠããããŸãã
|
This should not harm to much as spreading code like this should be considered as very bad style anyway.
|
ããããé
åžãããŠããã³ãŒãã§ã¯ããããèšæ³ã¯éåžžã«æªãã¹ã¿ã€ã«ã§ ãããšã¿ãªãããŠãããããªã®ã§ããã®å¶çŽã®åœ±é¿ã¯å€§ãããªãã¯ãã§ãã
|
Returning a value from an included file is still possible.
|
䜿çšãã§ããªããªã£ãä»ã®æ©èœãšããŠã¯ãPHP 3ã§ã¯ã»ãšãã©äœ¿çšãã ãŠããŸããããrequireã§èªã¿ããŸãããã¡ã€ã«ããå€ãè¿ããšãããã® ããããŸããincludeã§èªã¿èŸŒãŸãããã¡ã€ã«ããå€ãè¿ãããšã¯ PHP 4ã§ãå¯èœã§ãã
|
This features make it possible to let PHP 3 and PHP 4 run as concurrent modules in one Apache server.
|
æè¿ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ã¯ãããŒãžã§ã³ç®¡çåã³ã¹ã³ãŒãç£ç ãè¡ãæ©èœãæäŸãããŠããŸãããã®æ©èœã«ãããïŒã€ã®ApacheãµãŒãäž ã®ã¢ãžã¥ãŒã«ãšããŠPHP 3ãšPHP 4ãåæã«å®è¡ããããšãå¯èœã§ãã
|
Linux with recent binutils (binutils 2.9.1.0.25 tested)
|
ãã®æ©èœã¯ã以äžã®ãã©ãããã©ãŒã äžã§ã®åäœã確èªãããŠããŸãã
|
FreeBSD (3.2, 4.0 tested)
|
æè¿ã®binutils (binutils 2.9.1.0.25 ã§ãã¹ãæžã¿) ãåããLinux
|
To enable it, configure PHP3 and PHP4 to use APXS (--with-apxs) and the necessary link extensions (--enable-versioning).
|
Solaris 2.5以é
|
For example:
|
FreeBSD (3.2, 4.0 ã§ãã¹ãæžã¿)
|
Prev
|
ãã®æ©èœã䜿çšããã«ã¯ãPHP 3ããã³ PHP 4ã§APXS(--with-apxs)ããã³ å¿
èŠãªãªã³ã¯æ¡åŒµ(--enable-versioning)ãæå®ããŸãããã以å€ã®å Žåã éåžžã®åœä»€ã䜿çšãããŸããäŸãã°ã
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.