¥È¥Ã¥×   ÊÔ½¸ Åà·ë º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS

PHP

Last-modified: 2018-11-14 (¿å) 15:23:56 (2186d)
Top / PHP

PHP: Hypertext Preprocessor

java¤È»÷¤Æ¤¤¤Æ´Ö°ã¤¤¤ä¤¹¤¤ÅÀ

ʸ»úÎó¤ÎÏ¢·ë¤Ë¤Ï¡Ö.¡×(¥É¥Ã¥È)¤òÍѤ¤¤ë¡£

ʸ»úÎó¤ò°Ï¤¦»þ¡¢¡Ö"¡×¤È¡Ö'¡×¤ò°Õ¼±¤·¤Æ»È¤¤Ê¬¤±¤ë¡£

¡Ö+¡×¤Ë¤è¤ëÏ¢·ë¤Ï¡¢¿ôÃͱ黻¤È¤Ê¤ë¡£

Î㤨¤Ð¡Ö$a = "abc" + 5;¡×¤Î¾ì¹ç¡¢"abc"¤Ï¿ôÃͤǤʤ¤¤Î¤Ç£°¤ÈȽÃǤµ¤ì¡¢$a¤ÎÃͤϣµ¤È¤Ê¤ë¡£

À°¿ôÃͤò³ä¤ê»»¤·¤Æ¤â¡¢ÀÚ¤ê¼Î¤Æ¤é¤ì¤º¤Ë¾¯¿ô¤È¤Ê¤ë¡£

Î㤨¤Ð¡Ö5/3¡×¤ÎÃͤϡÖ1.66666666667¡×¤È¤Ê¤ë¡£

Äê¿ô¤ÎÄêµÁ¤Ïdefine´Ø¿ô¤òÍѤ¤¤ë¡£

»ÈÍÑÎã

   define(FOO, 123);

¥¯¥é¥¹ÆâÄê¿ô¤ÎÄêµÁ¤Ïconst¥­¡¼¥ï¡¼¥É¤òÍѤ¤¤ë¡£

»ÈÍÑÎã

   class Foo 
   {
       public const FOO = 123;
   }
   print("FOO: ".Foo::FOO);

ÀÅŪÊÑ¿ô¡¢ÀÅŪ¥á¥½¥Ã¥É¤Î¸Æ¤Ó½Ð¤·¤Ë¤Ï¡Ö::¡×¤òÍѤ¤¤ë¡£

»ÈÍÑÎã

   class Foo 
   {
       public static $foo = "abc";
       public static function funcFoo()
       {
           print("foo!");
       }
   }
   print(Foo::$foo);
   Foo::funcFoo();

¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò»È¤¦¾ì¹ç¡¢¡Öglobal¡×¤Îµ­½Ò¤¬É¬ÍפȤʤ롣

»ÈÍÑÎã

   function foo()
   {
       global $globalVar;
       $globalVar = "";
   }

¥ª¥Ö¥¸¥§¥¯¥È¤ÎÂåÆþ¤ÇPHP4¤ÈPHP5¤Ç»ÅÍͤ¬°ã¤¦¡£

PHP5¤Ïjava¤ÈƱ¤¸»²¾ÈÅϤ·¤Ç¤¹¡£
ÃÍÅϤ·¤Ë¤¹¤ë¾ì¹ç¡¢¡Ö$objectA = clone $objectB;¡×¤È¤·¤Þ¤¹¡£
PHP5¤ÏÃÍÅϤ·¤Ç¤¹¡£
»²¾ÈÅϤ·¤Ë¤¹¤ë¾ì¹ç¡¢¡Ö$objectA = &$objectB;¡×¤È¤·¤Þ¤¹¡£

»²¹Í¡§PHPÆâÉô¤ÎÊÑ¿ô¡¦ÇÛÎó°·¤¤¤Ë¤Ä¤¤¤Æ¤Ï¼¡¤Îµ­»ö¤¬Ê¬¤«¤ê¤ä¤¹¤«¤Ã¤¿¤Ç¤¹¡£
¤Ï¤¸¤á¤Ë-PHPÊÑ¿ô´ÉÍý²òÀâ(1)-»²¾È¤ÈÃÍÅϤ·¤ÎÌÀ³Î¤ÊÍý²ò¤Î¤¿¤á¤Ë

¥¢¥¯¥»¥¹½¤¾þ»Ò¤ÎÉÕ¤«¤Ê¤¤¥á¥ó¥ÐÊÑ¿ô¤Ï¡¢public¤È¤Ê¤ë¡£

PHP5¤Ç¤Ï¥á¥ó¥ÐÊÑ¿ô¤Ë¥¢¥¯¥»¥¹½¤¾þ»Òpublic, protected, private¤ò»ÈÍѤǤ­¤Þ¤¹¡£¤¿¤À¤·¡¢½¤¾þ»Ò¤òÉÕ¤±¤Ê¤¤¾ì¹ç¡¢¤ª¤è¤Ó¡¢var¤òÉղä·¤¿¾ì¹ç¡¢public¤¬Àë¸À¤µ¤ì¤¿¤â¤Î¤È¸«¤Ê¤µ¤ì¤Þ¤¹¡£

ÊØÍø¤Êµ¡Ç½

¡Ö`¡×(¥Ð¥Ã¥¯¥¯¥©¡¼¥È)¤Ç¤¯¤¯¤Ã¤Æ print¤¹¤ë¤È¡¢¥³¥Þ¥ó¥É¼Â¹Ô·ë²Ì¤ò½ÐÎϤǤ­¤ë¡£

   $cmd = `dir`;~
   print("<pre>".$cmd."<pre>");

ÊÌ¥Õ¥¡¥¤¥ë¤ÎPHP¥¹¥¯¥ê¥×¥È¤òÆɤ߹þ¤á¤ë¡£

´Ø¿ô̾ưºî
requireÌäÂ꤬ȯÀ¸¤·¤¿¾ì¹ç¡¢½èÍý¤òÃæ»ß
includeÌäÂ꤬ȯÀ¸¤·¤¿¾ì¹ç¡¢·Ù¹ð¤ò½Ð¤·¤Æ¡¢½èÍý¤ò·Ñ³
require_once£±ÃʤÀ¤±Æɤ߹þ¤àrequire´Ø¿ô
include_once£±ÃʤÀ¤±Æɤ߹þ¤àinclude´Ø¿ô

»ÈÍÑÎã

require(dirname(__FILE__) . "/../foo/foo.php");
// ¢¬ÁêÂХѥ¹¤Ï¤³¤Î¤è¤¦¤Ë½ñ¤­¤Þ¤¹

¥ê¥ó¥¯