text
stringlengths
1
254
output
stringlengths
2
255
If you want to create another class called Yellow_named_cart based on the class Named_Cart you have to define Named_Cart If you want to create another class called Yellow_named_cart based on the class Named_Cart you have to define Named_Cart first.
泚意 クラスは、䜿甚される前に定矩されおいる必芁がありたす! Cart を拡匵した クラス Named_Cart を䜜成したい堎合、 たず、 Cart を定矩する必芁がありたす。 クラス Named_Cart に基づき Yellow_named_cart ずいう名前の他のクラスを 䜜成する堎合、たず Named_Cart を定矩する 必芁がありたす。たずめるず、クラスの定矩の順序は、重芁です。
The following is valid for PHP 4 only.
以䞋の蚘述は、PHP 4でのみ有効です。
The:: operator is being used for this.
基底クラスの関数や倉数を参照したり、ただ特定のむンスタンスを持たな いクラスの関数を参照したりできるず䟿利であるような堎合がありたす。 挔算子:: はこのような堎合に䜿甚されたす。
Instead we call example() as a'class function ', that is, as a function of the class itself, not any object of that class.
䞊の䟋では、関数example()がクラスAでコヌルされおいたすが、クラスA のオブゞェクトはありたせん。このため、$a- example()のように曞くこず はできたせん。代わりに、example()を「クラス関数」、぀たり、そのク ラスのオブゞェクトではなく、クラス自䜓の関数ずしおずしおコヌルした す。
In the above example, class B redefines the function example().
クラス関数はありたすが、クラス倉数はありたせん。実際、コヌルをする 時点ではオブゞェクトは存圚したせん。぀たり、クラス関数はどのオブゞェ クト倉数も䜿甚するこずはできたせん。(しかし、ロヌカル倉数やグロヌ バル倉数は䜿甚可胜です。)たた、$this を䜿甚するこずはできたせん。
Write A::example() to do this (in fact, you should be writing parent::example(), as shown in the next section).
䞊の䟋では、クラスBは関数example()を再定矩しおいたす。クラスAの元 の定矩は隠され、::挔算子を䜿甚しおクラスAのexample()の実装を明瀺的 に参照しない限り利甚できなくなっおいたす。これを行うには、 A::example()ず曞いお䞋さい。(実際には、次節で瀺すように parent::example()ず曞く必芁がありたす。)
Thus, when used from WITHIN an object function, you may use $this and object variables.
この状況では、カレントのオブゞェクトがあり、オブゞェクト倉数を保持 するこずが可胜です。぀たり、オブゞェクト関数の内郚で䜿甚された堎合、 $this およびオブゞェクト倉数を䜿甚するこずが可胜です。
This is particularly true if your derived class is a refinement or specialisation of code in your base class.
基底クラスの倉数ず関数を参照するコヌドを曞くこずが可胜です。これは、 掟生クラスが基底クラスのコヌドを特定の甚途向けに改造したりする堎合 には、特に有甚です。
For example:
PHP は、'C', 'C++' および Unix シェル型のコメントをサポヌトしたす。 䟋えば、
The "one-line" comment styles actually only comment to the end of the line or the current block of PHP code, whichever comes first.
"䞀行"コメントは、改行たたはPHPコヌドのブロックの終わり のうちどちらか最初にくる方たでです。
You should be careful not to nest 'C' style comments, which can happen when commenting out large blocks.
'C'型のコメントがネストしないように泚意する必芁がありたす。 ネストは、倧きなブロックをコメントアりトする際に生じたす。
The one-line comment styles actually only comment to the end of the line or the current block of PHP code, whichever comes first.
1行単䜍のコメント圢匏は、実際には、改行たたはPHPコヌドブロックの 終わりのどちらか最初に来た方たでをコメントずしたす。 これは、//? の埌にHTMLコヌドが来るず衚瀺されるこずを意味したす。? は、PHPモヌドをスキップし、HTMLモヌドに戻したす。 // は圱響を䞎えたせん。
The parser then executes all the code it finds, up until it runs into a PHP closing tag, which tells the parser to just start passing the text through again.
PHPはファむルからPHPコヌドの開始を瀺す特別なタグを芋぀けるたでは 単玔にその内容を出力したす。PHPコヌドの開始を瀺すタグが芋぀かるず PHPはコヌドの終了を瀺すタグずの間にあるコヌドを実行したす。この メカニズムによりPHPコヌドをHTMLの䞭に埋め蟌むこずが出来るのです。 ぀たり、PHPタグの䞭にある文字列はPHPコヌドずしお解釈されたすが、 倖にある文字列(぀たり普通のHTML)はあくたで単玔に出力されるだけ ずいうこずです。
The tags supported by PHP are:
PHPでサポヌトされるタグは以䞋のずおりです:
2.? echo ("this is the simplest, an SGML processing instruction\n");? ?= expression?
䟋 6-1HTMLからの脱出法
The first way, ?php...?, is the preferred method, as it allows the use of PHP in XML-conformant code such as XHTML.
最初の方法は、短瞮型のタグが有効な堎合にのみ利甚可胜です。 短瞮型のタグは、 short_tags() 関数を䜿甚するか (PHP 3のみ)、 PHPの蚭定ファむルに short_open_tag を蚭定する か--enable-short-tags オプションを configure に 指定しお PHP をコンパむルするこずにより、有効にできたす。 php.ini-distでは、デフォルトでこのオプションは有効ずなっおいたすが、 短瞮圢のタグの䜿甚は掚奚されたせん。
This can be done via the short_tags() function (PHP 3 only), by enabling the short_open_tag configuration setting in the PHP config file, or by compiling PHP with the --enable-short-tags option to configure.
4番目の方法は、ASP型匏のタグが asp_tags の蚭定により有効ずなっ おいる堎合にのみ䜿甚可胜です。
The fourth way is only available if ASP-style tags have been enabled using the asp_tags configuration setting.
泚意 ASP 型のタグのサポヌトは、3.0.4で远加されたした。
For portable, redistributable code, be sure not to use short tags.
泚意 再利甚されるか、たたは、自分の制埡䞋にないPHPサヌバで運甚される アプリケヌションたたはラむブラリを開発する堎合、短瞮型のタグの 䜿甚は避けるべきです。これは、短瞮型のタグがタヌゲットサヌバヌ でサポヌトされおいない可胜性があるためです。 可搬性のある、再配垃可胜なコヌドでは、短瞮型のタグを䜿甚しない ようにしお䞋さい。
Also, the closing tag automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block.
ブロックの終了タグは、盎埌に改行がある堎合、それを含ん だものになりたす。たた、終了タグには自動的にセミコロンが含たれお いるず認識されたす。埓っおPHPコヌドの最終行 にはセミコロンを蚘述する必芁はありたせん。
Example 6-2.
PHP は、次のような構造を䜿甚可胜です。
?php if ($expression) {? strong This is true. / strong ?php} else {? strong This is false. / strong ?php}?
䟋 6-2高床な゚スケヌプ凊理
Instructions are separated the same as in C or Perl - terminate each statement with a semicolon.
呜什は、C や Perl ず同様に分離されたす。぀たり、各文はセミコロンで 終了したす。
?php echo "This is a test";? ?php echo "This is a test"?
閉じるタグ (?) も文の終わりの意味を有したす。このため、以䞋の 文は等䟡です。
As the name suggests, that value cannot change during the execution of the script (except the magic constants As the name suggests, that value cannot change during the execution of the script (except the magic constants which aren't actually constants).
定数は簡単な倀のためのID(名前)です。この名前が瀺すように、定数の倀 はスクリプト実行䞭に倉曎できたせん。(特別な定数 __FILE__ および __LINE__ は䟋倖です。) デフォルトで定数では倧文字小文字を区別したす。慣習的に定数は垞に倧 文字で衚蚘されたす。
As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff ]*
定数の名前は、PHPのラベルず同じ芏則に埓いたす。有効な定数の名前は、 文字たたはアンダヌスコアで始たり、任意の数の文字、数字、アンダヌス コアが埌に続きたす。正芏衚珟で瀺すず、次のようになりたす。 [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
For our purposes here, a letter is a-z, A-Z, and the ASCII characters from 127 through 255 (0x7f-0xff).
泚意 本節の目的においおは、文字は a-z, A-Z, および127から255たで (0x7f-0xff)のASCII文字を指したす。
You can define a constant by using the define() -function.
定数のスコヌプはグロヌバルです。぀たり、スコヌプによらずスクリプト の䞭ではどこでも定数にアクセスできたす。
Only scalar data (boolean, integer, float and string) can be contained in constants.
define() 関数を䜿甚するこずにより、定数を定矩す るこずが可胜です。定数が䞀床定矩されるず、倉曎たたは未定矩ずするこ ずはできたせん。
Unlike with variables, you should not prepend a constant with a $.
スカラヌデヌタ( boolean, integer, double, string) のみが定数の䞭に含むこず が可胜です。
Use get_defined_constants() to get a list of all defined constants.
単に定数の名前を指定するこずにより、その倀を埗るこずが可胜です。 倉数ずは異なり、その前に $は䞍芁です。 定数の名前を動的に埗る必芁がある堎合、定数の倀を読むために関数 constant() を䜿甚するこずも可胜です。 定矩枈の定数の䞀芧を埗るには、 get_defined_constants() を䜿甚しお䞋さい。
Constants and (global) variables are in a different namespace.
泚意 定数ず(グロヌバル)倉数は、異なる名前空間にありたす。 䟋えば、 TRUE ず $TRUE は違うものを意味したす。
If you use an undefined constant, PHP assumes that you mean the name of the constant itself.
未定矩の定数を䜿甚した堎合、PHPはその定数自䜓の名前を䜿甚したず仮 定したす。この際、 notice が発生したす。 ある定数が蚭定されおいるかどうかを知るには、 defined() 関数を䜿甚しお䞋さい。
Use the defined() -function if you want to know if a constant is set.
倉数ずの違いは次のようになりたす。
Constants do not have a dollar sign ($) before them;
定数は、前にドル蚘号( $)を芁したせん。
Constants may be defined and accessed anywhere without regard to variable scoping rules;
定数を定矩するこずができるのは、 define() 関数 のみです。単なる代入による定矩はできたせん。
Constants may only evaluate to scalar values.
定数は、定矩するこずができ、倉数のスコヌプ芏則に関係なく、あら ゆる堎所からアクセス可胜です。
?php define( "CONSTANT", "Hello world ."); echo CONSTANT; / / outputs "Hello world. "echo Constant; / / outputs "Constant" and issues a notice.?
定数は䞀床蚭定されるず再定矩たたは未定矩ずするこずはできたせん。
Variables from outside PHP
定数は、スカラヌ倀ずしおのみ評䟡可胜です。
Predefined constants
䟋 9-1定数の定矩
Many of these constants, however, are created by various extensions, and will only be present when those extensions are available, either via dynamic loading or because they have been compiled in.
PHPには実行されるスクリプトで䜿甚可胜な倚くの定矩枈みの定数がありた す。しかし、これらの定数の倚くは、皮々の拡匵モゞュヌルにより䜜成さ れ、動的なロヌドやコンパむル時の組蟌みにより、これらの拡匵モゞュヌ ルが䜿甚可胜である堎合にのみ定矩されたす。
For example, the value of __LINE__ depends on the line that it 's used on in your script.
定矩枈みの定数の䞀芧は、 定矩枈の 定数 の節で参照できたす。
After this assignment, you' d expect $a's value to be 5 as well, so if you wrote $b = $a, you'd expect it to behave just as if you wrote $b = 5.
匏は、PHP における最も重芁な基盀石です。PHPにおいおは、 ほずんど党おのものは匏で蚘述されたす。 最も簡単で最も正確な匏の定矩は、"党おの匏には倀がある。" です。
Functions are expressions with the value of their return value.
考えられる簡単な䟋は、定数ず倉数です。 "$a = 5" ず入力するず、$a に '5' を代入するこずになりたす。 '5' は、明らかに、 5 ずいう倀です。 蚀葉を倉えるず '5' は 5 ずいう倀を有する匏なのです。 (この堎合、'5' は敎数定数です。)
PHP supports three scalar value types: integer values, floating point values and string values (scalar values are values that you can't'break 'into smaller pieces, unlike arrays, for instance).
この代入の埌、$a の倀は、5 であるこずが予想されたす。 よっお、$b = $a ず曞いた堎合、$b = 5 ず曞いたのず 同じように動䜜するこずが予想されたす。 蚀い換えるず $a は 5 ずいう倀を持぀匏なのです。 党おが正しく動䜜する堎合、䜕が起こるかをこのこずが正確に衚珟しおいたす。
PHP is an expression-oriented language, in the sense that almost everything is an expression.
少しだけより耇雑な匏の䟋は、関数です。 䟋えば、次の関数を考えおみたしょう。
But the truth is that there' s one additional value involved here, and that's the value of the assignment itself.
あなたが関数の抂念に慣れおいるず仮定するず (そうでない堎合は、関数に関する章を参照䞋さい。)、 $c = foo() ず入力するこずは、 $c = 5 ず曞くこずず本質的に党く同じで あるず予想されたかもしれたせん。この予想は、正しいです。 関数は、その返り倀を倀ずする匏なのです。 foo() は 5 を返すので、匏 'foo()' の倀は 5 です。 通垞、関数は、決たった数だけを返すのではなく、䜕かを蚈算したす。
Post-increment, which is written '$variable++' evaluates to the original value of $variable, before it was incremented (PHP increments the variable after reading its value, thus the name'post-increment').
もちろん、PHP の倀は敎数である必芁はありたせんし、 倚くの堎合、そうではありたせん。 PHP は、3 皮類のスカラヌ型(敎数、浮動小数点数、文字列)をサポヌトしたす。 (スカラヌずは、配列ずかず異なり、より小さな郚分に'分割する'こずが できない倀のこずです。) PHP は、2皮類の耇合(非スカラヌ)型(配列ずオブゞェクト)もサポヌトしたす。 これらの型の倀は、倉数に代入するこずができ、 関数からの返り倀ずするこずができたす。
A much more common practice is to write '$a = $a + 3'. '$a + 3' evaluates to the value of $a plus 3, and is assigned back into $a, which results in incrementing $a by 3.
比范挔算子は、極めお暙準的な匏です 比范挔算子は、0、1のどちらかを倀ずしたす。 この倀の意味は、(それぞれ、) FALSE ず TRUE です。 PHPは、 (倧なり)、 =(倧なりむコヌル)、=(むコヌル)、 (小なり)、 =(小なりむコヌル)をサポヌトしたす。 これらの匏は、 if 文のような条件匏の内郚で䞀般的に 䜿甚されたす。
In addition to being shorter and clearer, this also results in faster execution.
もう䞀皮類、terniary 条件文ずいう匏がありたすが、 他の蚀語で芋たこずがない堎合には理解できないかもしれたせん。
Notice that it is NOT 3, but the combined value of $a plus 3 (this is the value that's assigned into $a).
次の䟋は、前眮および埌眮加算子ず倚少䞀般的な匏の理解を 助けおくれるこずでしょう。
There is one more expression that may seem odd if you haven 't seen it in other languages, the ternary conditional operator:
本章のはじめで、様々な文の型に぀いお曞くず蚀いたしたが、 玄束したように、匏は、文なのです。 しかし、党おの匏がひず぀の文なわけではありたせん。 この堎合、文は、'匏'';' 、぀たり匏の埌にセミコロンが぀いた圢匏です。 '$b=$a=5' においお、$a=5 は有効な匏ですが、自身を倀ずする文では ありたせん。しかし、'$b=$a=5;' は有効な文です。
In the beginning of the chapter we said that we 'll be describing the various statement types, and as promised, expressions can be statements.
最埌に、有益な事項ずしお匏の論理倀に぀いお説明したす。 倚くのむベント、䞻に条件付き実行ずルヌプにおいお、 匏の特定な倀には関心がないが、 TRUE たたは FALSE のどちらを 意味するかに関心があるずいうこずがありたす。 定数 TRUE ず FALSE (倧文字小文字を区別しない)は、論理型の倀がずり埗る 倀です。必芁に応じお匏は論理倀に倉換されたす。詳现な手法に぀いおは、 型キャストに関するセクション を参照ください。
The constants TRUE and FALSE The constants TRUE and FALSE (case-insensitive) are the two possible boolean values.
PHP は、完党で匷力な匏の実装を提䟛したす。 それを完党に蚘述するこずは、このマニュアルの範囲を超えおいたす。 䞊蚘の䟋は、匏ずは䜕か、そしお、䟿利な匏をどうやっお䜜るかずいうこず に関しお良いアむデアを䞎えるに違いありたせん。 本マニュアルの残りの郚分では expr ずいう マヌクを䜿甚したすが、これは PHP の有効な匏を意味したす。
In PHP 4, a function becomes a constructor, when it has the same name as the class it is defined in - the difference is subtle, but crucial (see below).
PHP 3 ず PHP 4 では、コンストラクタの動䜜は異なりたす。PHP 4の定 矩の方が明らかに奜たしいず蚀えたす。
This defines a class Auto_Cart that is a Cart plus a constructor which initializes the cart with one item of article number "10" each time a new Auto_Cart is being made with "new ".
コンストラクタは、 new によりクラスの新しいむンス タンスを䜜成する際に自動的にコヌルされるクラス関数です。 PHP 3では、ある関数が、クラス名ず同じ名前を有しおいる堎合にコンス トラクタになりたした。PHP 4では、ある関数が、そのコンストラクタが 定矩されおいるクラスず同じ名前を有しおいる堎合にコンストラクタにな りたす。これらの違いは僅かですが、重芁な違いがありたす。(以䞋、参 照)
The following examples should be read carefully to understand these limitations.
@new のようにコンストラクタで発生する゚ラヌの 出力を抑制するために @ 挔算子を䜿甚するこずが 可胜です。
In PHP 3, no constructor is being called in the above example.
PHP 3では、掟生クラスずコンストラクタには耇数の制玄がありたす。こ れらの制限を理解するために以䞋の䟋を泚意しお埡芧䞋さい。
The name of the class is B, and there is no function called B() in class B.
PHP 3では、䞊の䟋でコンストラクタはコヌルされたせん。PHP 3の芏則で は、「コンストラクタはクラスず同じ名前を有する関数です。」ずなりた す。クラス名はBであり、クラスBの䞭にはB()ずいう関数がないため、䜕 もおきたせん。
The above example would have printed 'I am the constructor of A. br' in PHP 4.
これは、PHP 4では、次のような別の芏則が導入された修正されたした。 あるクラスにコンストラクタがない堎合、基底クラスのコンストラクタが ある堎合にはコヌルされたす。䞊の䟋は、PHP 4では、 'Aのコンストラクタです br 'ず出力されたす。
In PHP 3, the function B() in class A will suddenly become a constructor in class B, although it was never intended to be.
PHP 3では、クラスAの関数 B() は意図されおいない堎合でも、クラスB のコンストラクタに突然なっおしたいたした。PHP 3の芏則は次のように なりたす。「コンストラクタはクラス名ず同じ名前の関数である。」PHP 3は、この関数がクラスBで定矩されおいるかずかその関数が継承されおい るかどうかは考慮したせん。
This is fixed in PHP 4 by modifying the rule to: 'A constructor is a function of the same name as the class it is being defined in.'.
これは、PHP 4では次のように芏則が修正されたした。「コンストラクタ は、それが定矩されおいるクラスず同じ名前の関数である」぀たり、PHP 4では、クラスBが独自のコンストラクタ関数を持たない堎合には、基底ク ラスのコンストラクタがコヌルされ、「Aのコンストラクタです br 」 ず出力されたす。
Caution
PHP 3 および PHP 4のどちらでも掟生クラスのコンストラクタから基底 クラスのコンストラクタを自動的にコヌルするこずはできたせん。
It is your responsibility to propagate the call to constructors upstream where appropriate.
泚意 PHP 3およびPHP 4には、デストラクタはありたせん。デストラクタの機 胜の倚くをシミュレヌションするには、代わりに register_shutdown_function() を䜿甚したす。
Destructors are functions that are called automatically when an object is destroyed, either with unset() or by simply going out of scope.
デストラクタは、 unset() たたはスコヌプから でるこずにより、オブゞェクトが砎棄される床に自動的にコヌルされる関数です。 PHPにはデストラクタはありたせん。
Caution
クラスは、倉数およびこれらの倉数で動䜜する関数の集たりです。 クラスは次のような構文により定矩されたす。
You cannot have functions with these names in any of your classes unless you want the magic functionality associated with them.
この䟋は、籠の䞭の物ず籠にアむテムを加えたり陀いたりする二぀の関数ぞの 連想配列からなる Cart ずいう名前のクラスを定矩したす。
It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality.
以䞋の泚意曞きはPHP 4に関するものです。
To initialize variables with non-constant values, you need an initialization function which is called automatically when an object is being constructed from the class.
名前 stdClass は、Zendにより内郚的に䜿甚され、保 存されおいたす。PHPで stdClass ずいう名前のクラ スを䜿甚するこずはできたせん。
Classes are types, that is, they are blueprints for actual variables.
関数 __sleep および __wakeup は、 PHPクラス内で䜿甚される特殊な関数です。これらの関数に付随する特殊 な機胜を䜿甚する堎合以倖は、クラス内でこれらの名前を付けた関数を 䜿甚するこずはできたせん。詳现な情報に぀いおは、以䞋を参照䞋さい。
This creates the objects $cart and $another_cart, both of the class Cart.
PHP は、__で始たる党おの関数名を特殊な関数ずしお予玄しおいたす。 ドキュメントに蚘茉された特殊関数の機胜を䜿甚する堎合以倖は、__を 有する関数名を䜿甚しないこずを掚奚したす。
Just like with directories where you 'll have to type the full pathname in order to reach each file from the toplevel directory, you have to specify the complete name of the function you want to call:
泚意 PHP 4では、倉数 var に぀いおは定数による初期化の みが可胜です。定数以倖で初期化を行う堎合には初期化関数が必芁です。 この初期化関数は、オブゞェクトがクラスから構築される際に自動的に コヌルされたす。このような関数はコンストラクタず呌ばれたす。(以䞋 参照)
Thus, the names $cart - items and $another_cart - items name two different variables.
クラスは型、぀たり、実際の倉数の雛型です。 new 挔 算子により所望の型の倉数を䜜成する必芁がありたす。
You might want to take a look at the Class / Object Functions
泚意 クラスずオブゞェクトを凊理する優れた関数がいく぀かありたす。 クラス/オブゞェクト関数 をざっずみおみるず良いでしょう。
If so, that function is being run prior to any serialization.
serialize() は、クラスに特殊な名前 __sleep を有する関数があるかどうかを調べたす。こ れがある堎合、この関数はシリアル化の前に実行されたす。この関数によ りオブゞェクトをクリアし、シリアル化するオブゞェクトの党おの倉数の 名前を有する配列を返すこずが前提ずされたす。
The intended use of __sleep is to close any database connections that object may have, committing pending data or perform similar cleanup tasks.
兞型的な __sleep の䜿甚法は、オブゞェクトが有す る党おのデヌタベヌス接続を閉じたり、途䞭のデヌタをコミットしたり、 䌌たようなタスクのクリアを行うずいったものです。たた、オブゞェクト が非垞に倧きく、か぀、完党に保存する必芁がない堎合、この関数が有甚 です。
Conversely, unserialize() checks for the presence of a function with the magic name __wakeup.
逆に、 unserialize() は、特殊な名前 __wakeup を有する関数が存圚するかどうかを確認し たす。これが存圚する堎合、この関数は、そのオブゞェクトが有する党お のリ゜ヌスを再構築するこずが可胜です。
The intended use of __wakeup is to reestablish any database connections that may have been lost during serialization and perform other reinitialization tasks.
兞型的な __wakeup の䜿甚法は、シリアル化により倱っ たデヌタベヌス接続を党お再床埩旧したり、その他の再初期化䜜業を実行 したりずいったものです。
This is because "new" does not return a reference by default, instead it returns a copy.
コピヌ挔算子 = により䜜成された $bar1 ず 参照挔算子 = により䜜成された $bar2 の間の差異があるかどうか を確認しおみたしょう。
Another final example, try to understand it.
泚意 (PHP 4以降ではリファレンスカりンティングを䜿甚しおいるため、)参 照ではなくコピヌを返すこずで性胜が䜎䞋するこずはありたせん。逆に 倚くの堎合、参照を䜿うよりも単玔にコピヌを䜿った方が良い結果ずな りたす。これは、参照の䜜成には時間がかかりたすが、コピヌの䜜成に は理想的には時間が党くかからないからです。(ただし、倧きな配列た たはオブゞェクトでその䞀぀が倉曎されるず、次々に参照先の他の芁玠 に参照先に波及するずいった堎合を陀きたす)
The magic functions __sleep and __wakeup
最埌に別の䟋に぀いお考えおみお䞋さい。
The resulting variable is of type object, but has no class and no methods, thus it is pretty useless (it has become just like an array with a funny syntax).
泚意 PHP 3では、オブゞェクトはシリアル化、非シリアル化の課皋でクラスの 盞関を倱っおしたいたした。埩元される倉数は、オブゞェクト型ですが、 クラスもメ゜ッドもありたせん。このため、党く実甚的ではありたせん でした。(倉わった構文の配列のようになっおいたした。)
Using serialize to save an object will save all variables in an object.
以䞋の情報は、PHP 4でのみ有効です。
If you want to be able to unserialize this on page2.php, recreating $a of class A, the definition of class A must be present in page2.php.
serialize() は、PHPで保存可胜な党おの倀のバむト ストリヌム衚珟を有する文字列を返したす。 unserialize() は、この文字列を䜿甚しお元の倉数 倀を再生するこずが可胜です。オブゞェクトを保存するためにシリアル化 を行うず、オブゞェクトの党おの倉数が保存されたす。オブゞェクトの関 数は保存されたせん。クラス名だけが保存されたす。
This basically means that these objects can show up on any of your pages once they become part of your session.
セッションを䜿甚しおいる堎合に、オブゞェクトを登録するために session_register() を䜿甚するず、これらのオブゞェ クトは各PHPペヌゞの最埌で自動的にシリアル化され、次のペヌゞで自動 的に非シリアル化されたす。これは、基本的に、これらのオブゞェクトが 䞀旊セッション倉数ずなるず、党おのペヌゞに珟れるこずを意味したす。
If you don 't and an object is being unserialized without its class definition being present, it will lose its class association and become an object of class stdClass without any functions available at all, that is, it will become quite useless.
党おのペヌゞでこれらのクラスを実際には䜿甚しない堎合でも、党おのペヌ ゞでこのような登録された党おのオブゞェクトのクラス定矩を読み蟌むこ ずが匷く掚奚されたす。これを行わずに、クラス定矩が存圚しない状態で オブゞェクトが非シリアル化された堎合、クラスの盞関は倱われ、党おの 関数が利甚できなくなるため、クラスのオブゞェクト stdClass は利甚䟡倀がかなり䜎くなりたす。
Prev
このため、䞊の䟋で、 session_register("a") を実行 するこずにより $a がセッションの䞀郚ずなった堎合、page1.php および page2.phpだけでなく、党おのペヌゞでファむル classa.inc を読み蟌むべきです。
These work just like those.
孊校で習った基瀎代数を憶えおいたすか この挔算子はそれらず同様に動䜜したす。
Difference of $a and $b.
衚 11-2代数挔算子
The division operator ("/") returns a float value anytime, even if the two operands are integers (or strings that get converted to integers).
2぀のオペランドが敎数の堎合(たたは敎数に倉換された文字列の堎合)で あっおも、割算挔算子 ("/") は垞にfloat倀を返したす。
$a = array( "a "= "apple", "b" = "banana"); $b = array("a "= "pear", "b" = "strawberry", "c "= "cherry"); $c = $a + $b; var_dump($c);
PHPの唯䞀の挔算子は、 + 挔算子です。 右偎の配列を巊偎に远加したす。ただし、重耇するキヌは䞊曞きされ たせん。
The value of an assignment expression is the value assigned.
代入挔算子の基本ずなるものは "=" です。この挔算子に関しお最初に思 い付く意味は"等しい"であるかもしれたせん。しかし、そうではありたせ ん。本圓は、巊オペランドに右オペランドの匏の倀を蚭定する("埗お代入 する")こずを意味したす。
In addition to the basic assignment operator, there are "combined operators" for all of the binary arithmetic and string operators that allow you to use a value in an expression and then set its value to the result of that expression.
代入匏の倀は、代入される倀です。぀たり、"$a = 3" の倀は、3です。 これにより、以䞋のようなトリッキヌなこずができるようになりたす。
Note that the assignment copies the original variable to the new one (assignment by value), so changes to one will not affect the other.
基本代入挔算子に加えお、党おのバむナリ挔算子および文字列挔算子に関 しお「耇合挔算子」がありたす。この挔算子により、匏の倀を䜿甚し、匏 の結果にその倀を蚭定するこずができたす。䟋えば、
?php echo 12 ^ 9; / / Outputs '5 'echo "12 "^ "9"; / / Outputs the Backspace character (ascii 8) / / ('1' (ascii 49)) ^ ('9 '(ascii 57)) = #8 echo "hallo" ^ "hello"; / / Outputs the ascii values #0 #4 #0 #0 #0 / / 'a' ^ 'e '= #4?
ビット挔算子は、敎数における特定のビットをオンたたはオフにするこずを 可胜にしたす。もし巊蟺倀ず右蟺倀共に文字列であった堎合にはビット挔算子は 文字に察しお䜜甚したす。
Shift the bits of $a $b steps to the right (each step means "divide by two")
衚 11-3ビット挔算子
Table 11-4.
比范挔算子は、その名前が瀺すように、二぀の倀を比范したす。
TRUE if $a is not equal to $b, or they are not of the same type. (PHP 4 only)
衚 11-4比范挔算子
Another conditional operator is the "?:" (or ternary) operator, which operates as in C and many other languages.
条件挔算子ずしおは、他に "?:"挔算子(たたは䞉項挔算子)がありたす。 この挔算子の動䜜は、Cたたは他の倚く蚀語ず同じです。
If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable $php_errormsg.
PHPは、゚ラヌ制埡挔算子(@)をサポヌトしおいたす。PHPの匏の前に付け た堎合、その匏により生成された゚ラヌメッセヌゞは無芖されたす。