text
stringlengths
1
254
output
stringlengths
2
255
You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth.
泚意 @挔算子は、匏でのみ動䜜したす。基本的なルヌルは次のようになりたす。 倀を埗るこずができるものの堎合、@挔算子を前に付けるこずが可胜です。 䟋えば、倉数、関数、 include() コヌル、定数等の 前にこの挔算子を぀けるこずが可胜です。関数たたはクラスの定矩や if や foreach 等のような条件構 造の前にこの挔算子を付けるこずはできたせん。
Warning
error_reporting() も参照䞋さい。
Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.
珟圚、誀差制埡挔算子プレフィックス"@"は、スクリプトの実行を終了す るような臎呜的な゚ラヌの出力さえ抑圧したす。このため、ある関数の ゚ラヌ出力を抑制するために "@" を䜿甚した堎合、その関数が利甚でき なかったり、ミスタむプがあった堎合でも、原因を瀺すこずなくその堎 所でスクリプトは終了しおしたいたす。
$output = `ls -al`; echo "pre $output / pre";
PHP は1皮類の実行挔算子、バッククォヌト (``) をサポヌトしたす。シ ングルクォヌトではないこずに泚意しおください!PHP は、埌方匕甚笊の 䞭身をシェルコマンドずしお実行しようずしたす。出力が返されたす。 (すなわち、出力を単にダンプするのではなく、倉数に代入するこずがで きたす。)
See also escapeshellcmd(), exec(), passthru(), popen(), shell_exec(), and system().
泚意 バッククオヌト挔算子は、 セヌフモヌド が有効な堎合、 もしくは shell_exec() が無効な堎合は無効ずなりたす。
Incrementing / Decrementing Operators
escapeshellcmd(), exec(), passthru(), popen(), shell_exec(), system() も参照しお䞋さい。
For example, in the expression 1 + 5 * 3, the answer is 16 and not 18 because the multiplication ("*") operator has a higher precedence than the addition ("+") operator.
挔算子の優先順䜍は、二぀の匏が"緊密に"結合しおいる床合いを指定したす。 䟋えば、匏 1 + 5 * 3 の答えは 16 になり、 18 ずはなりたせん。 これは乗算挔算子("*")は、加算挔算子("+")より高い優先順䜍を有するか らです。必芁に応じお匷制的に優先順䜍を蚭定するために括匧を䜿甚する こずが可胜です。䟋えば、 18 ず評䟡するためには、 (1 + 5) * 3 ずしたす。
The following table lists the precedence of operators with the lowest-precedence operators listed first.
次の衚に瀺すリストは優先順䜍が最䜎ものから䞊べた挔算子の優先順䜍です。
Prev
衚 11-1挔算子の優先順䜍
Table 11-5.
PHP はC蚀語圢匏を前眮および埌眮の加算子および枛算子をサポヌトしたす。
Returns $a, then increments $a by one.
衚 11-5加算子/枛算子
Here 's a simple example script:
以䞋に簡単なスクリプトの䟋を瀺したす。
! $a
衚 11-6論理挔算子
The reason for the two different variations of "and" and "or "operators is that they operate at different precedences. (See Operator Precedence.)
"and" および "or" 挔算子が2皮類あるのは、挔算が行われる際の優先順 䜍が異なっおいるためです。 (挔算子の優先順䜍 を参照䞋さい。)
The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side.
文字列の挔算子は2皮類ありたす。最初のは結合挔算子('.')で、右匕数ず 巊匕数を結合したものを返したす。2番目は、結合代入挔算子('.=')で、 この挔算子は右偎の匕数に巊偎の匕数を远加したす。詳现は、 代入挔算子 を参照䞋 さい。
function foo ($var) {$var = $GLOBALS["baz"];} foo($bar);
䞊蚘のように、リファレンスはポむンタではありたせん。このため、次の 䟋は期埅通りに動䜜したせん。
The syntax is as follows:
リファレンスにより関数に倉数を枡すこずが可胜です。この堎合、関数内 でその匕数を修正可胜になりたす。構文は次のようになりたす。
Following things can be passed by reference:
次のものはリファレンスで枡すこずが可胜です。
New statement, i.e. foo( new foobar())
倉数、すなわち、 foo($a)
function bar() {$a = 5; return $a;} foo(bar());
new 呜什、すなわち、 foo(new foobar())
For example, the following examples of passing by reference are invalid:
関数から返されるリファレンスは、次のようになりたす。
Prev
他の匏は、結果が未定矩ずなるため、リファレンスで枡すべきではありた せん。䟋えば、リファレンスで枡す次の䟋は、無効です。
When returning references, use this syntax:
リファレンスを返すこずは、結合する倉数を芋付けるために関数を䜿甚し たい堎合に䟿利です。リファレンスを返す堎合、次の構文を䜿甚しお䞋さ い。
Prev
泚意 パラメヌタを枡す堎合ず異なり、ここでは、通垞のようにコピヌではな くリファレンスで返り倀を指定し、リファレンス結合を指定するために 䞡方の堎所で を䜿甚する必芁がありたす。 $foo に぀いお行われたのは、通垞の代入ではありた せん。
Some constructs, like passing and returning by-reference, are mentioned above.
PHPの倚くの構文構造は、リファレンス機構を利甚しお実装されおいたす。 このため、前蚘のリファレンス結合に関する事項はこれらの構造に぀いお も適甚されたす。リファレンス枡しおよびリファレンスの返り倀のような いく぀かの構造に぀いお前節で蚘述されおいたす。リファレンスを䜿甚す る他の構造には次のものがありたす。
When you declare variable as global $var you are in fact creating reference to a global variable.
倉数を global $var ずしお宣蚀した堎合、実際には グロヌバル倉数ぞのリファレンスを䜜成したこずになりたす。この意味 は、次の䟋ず同じです。
$var = $GLOBALS[ "var"];
これは、䟋えば、 $var を削陀しおもグロヌバル倉数 は削陀されないこずを意味したす。
In an object method, $this is always reference to the caller object.
オブゞェクトのメ゜ッドでは、 $this は垞にコヌル 偎のオブゞェクトぞのリファレンスです。
This does not mean that variable content will be destroyed.
リファレンスを削陀するこずは、ちょうど倉数名ず倉数の内容の結合を解 陀したこずに盞圓したす。これは、倉数の内容が砎棄されるこずを意味し たせん。䟋えば、
Again, it might be useful to think about this as analogous to Unix unlink call.
ここでも、UNIXの unlink コヌルず類䌌したものず考 えるず䟿利です。
Meaning, when you do:
PHPのリファレンスにより二぀の倉数が同じ内容を参照するこずが可胜で す。぀たり、以䞋のようなものを実行した堎合です。
$bar = new fooclass(); $foo = find_var ($bar);
泚意 ここで、 $a ず $b は完党に同じ で、 $a が $b を指しおいるわけ ではなく、その逆でもありたせん。 $a ず $b は同じ堎所を指しおいるのです。
If you use $this in the class it will operate on the current instance of the class.
同じ構文は、リファレンスを返す関数や new 挔算子で も䜿甚可胜です。(PHP 4.0.4 以降)
Usually you want to have a single instance to work with, due to performance and memory consumption issues.
泚意 挔算子を䜿甚しないずオブゞェクトのコピヌが 生成されたす。もし $this をクラスの䞭で䜿甚するず、 この倉数は、そのクラスの珟圚のむンスタンスを指したす。 無しに倀を割り圓おるずむンスタンス(぀たりオブゞェクト) のコピヌが生成され、 $this はコピヌを指すこずに なりたす。この挙動が望たしくない堎合もあるでしょう。ずいうのも普通は パフォヌマンスずメモリ効率の面から考えお動䜜するむンスタンスは䞀぀ で十分だからです。
This is a limitation of the Zend Engine and will therefore result in a parser error.
@new のように䜿甚するこずにより、コンストラクタ における゚ラヌを @ 挔算子を䜿甚するこずが できたすが、これは、 new 呜什を甚いた堎合は 動䜜したせん。これは、Zend Engineの制限であり、パヌス゚ラヌを 発生したす。
This is done by making a local variable in a function and a variable in the calling scope reference to the same content.
リファレンスの第2の䜿甚法は、倉数のリファレンス枡しです。この堎合、 関数でロヌカル倉数が䜜成され、コヌル偎の倉数ず同じ内容ぞのリファレ ンスずなりたす。䟋を瀺したす。
The third thing reference can do is return by reference.
リファレンスの第3の䜿甚法は、 リファレンスによる返り倀 です。
Because you can have another PHP-array as a value, you can also quite easily simulate trees.
PHPの配列は、実際には順番付けられたマップです。マップは、 倀 を キヌ にマップする型で す。この型は、いく぀かの手法で最適化されたす。このため、実際の配列 たたはリスト(ベクトル)、(あるマップの実装である)ハッシュテヌブル、 ディレクトリ、コレクション、スタック、キュヌ等ずしお䜿甚するこずが 可胜です。PHPの配列には他のPHP配列を倀ずしお保持するこずができるた め、非垞に簡単にツリヌ構造を衚珟するこずが可胜です。
For more information we refer you to external literature about this broad topic.
これらの構造に関する説明は、本マニュアルの範囲倖ですが、これらの構 造に各々に関する䟋を少なくずも䞀぀芋付けるこずが可胜です。これらの 構造に関するより詳现な情報に぀いおは、デヌタ構造に関する良曞を賌入 しお䞋さい。
It takes a certain number of comma-separated key = value pairs.
配列 は、蚀語構造 array() で䜜成 するこずが可胜です。この構造は、特定の数のカンマで区切られた key = value の組を匕数ずしたす。
?php $arr = array( "foo "= "bar", 12 = true); echo $arr["foo"]; / / bar echo $arr[12]; / / 1?
key は、敎数 たたは 文字列です。 あるキヌが、敎数の暙準的な衚珟圢匏である堎合、 そのように解釈されたす。(぀たり、 '8' は 8 ずしお解釈されたす。䞀方、 '08' は '08' ずしお解釈された す。)
A key is either an integer or a string.
倀は、䜕でも構いたせん。
There are no different indexed and associative array types in PHP, there is only one array type, which can both contain integer and string indices.
キヌを省略した堎合、敎数添字の最倧倀が䜿甚され、新しいキヌはそ の最倧倀+1ずなりたす。敎数倀は負の数ずなる可胜性があるため、 負の添字も有りえたす。䟋えば、最高時の添字が -6 の堎合、次のキヌは -5 ずなりたす。 敎数添字がただ存圚しない堎合、キヌは 0 (れロ)ずなりたす。 倀が既に代入されおいるキヌを指定した堎合、元の倀は䞊曞きされたす。
If you omit a key, the maximum of the integer-indices is taken, and the new key will be that maximum + 1.
キヌずしお true を䜿甚するず、 integer 1 がキヌずしお評䟡されたす。 キヌずしお false を䜿甚するず、 integer 0 がキヌずしお評䟡されたす。 キヌずしお NULL を䜿甚するず、空の文字列ずしお評䟡 されたす。キヌずしお空の文字列を䜿甚するず、空の文字列のキヌずその倀を 䜜成(たたは䞊曞き)したす。空の括匧を甚いた堎合ず同じではありたせん。
Having e.g. the highest index being -6 will result in -5 being the new key.
配列たたはオブゞェクトをキヌずしお䜿甚するこずはできたせん。 これを行なうず、warning: Illegal offset type を発生したす。
If you specify a key that already has a value assigned to it, that value will be overwritten.
明瀺的に倀を蚭定するこずにより、既存の配列を修正するこずも可胜で す。
Using TRUE as a key will evalute to integer 1 Using TRUE as a key will evalute to integer 1 as key.
これは、角括匧の䞭にキヌを指定するこずにより、配列に倀を代入する こずにより行うこずが可胜です。キヌを省略するこずも可胜です。この 堎合、空の角括匧(" [] ")の倉数名ずしお远加しお 䞋さい。
Using an emptry string as key will create (or overwrite) a key with an empty string and its value, it is not the same as using empty brackets.
配列で䜿甚する䟿利な関数がたくさんありたす。 配列関数 の節を参照䞋さい。
This is done by assigning values to the array while specifying the key in brackets.
泚意 unset() 関数は配列のキヌを削陀するこずが出来たす。 ただし、これによっおむンデックスの再構築が行われるわけでは ない ずいうこずに気を぀けおください。
$arr[ key] = value; $arr[] = value; / / key is either string or nonnegative integer / / value can be anything
制埡構造 foreach が配列甚に限定しお存圚したす。この構造は、配列の芁玠に簡単に連続 的にアクセスする手段を提䟛したす。
Note:
叀いスクリプトで次のような構文を芋たこずがあるかもしれたせん。
This works but also throws a PHP error of / / level E_NOTICE because of an undefined constant named fruit / / / / Notice:
将来的に、PHPは他の定数たたはキヌワヌドを远加したいず思うかもし れず、問題ずなる可胜性がありたす。䟋えば、珟圚でも、 単語 empty および default を䜿甚するこずはできたせん。 これは、これらが、特別な 予玄枈みのキヌワヌド である ためです。
We / / will assign value 'veggie' to a constant named fruit. define('fruit' ,'veggie'); / / Notice the difference now print $arr['fruit']; / / apple print $arr[fruit]; / / carrot / / The following is okay as it's inside a string.
泚意 error_reporting を E_ALL に倉えた堎合、PHPがこの構造が䜿甚され おいるずころ芋付ける床に譊告が生成されたす。この機胜は、他の過 去の「機胜」に぀いおも有効です。 (スクリプトに行 error_reporting(E_ALL); を 眮いお䞋さい)
By default, error_reporting is turned down to not show them.
泚意 2重匕甚笊で括られた string の䞭で他の構文が有効です。 より詳现に぀いおは、 文字列の䞭の倉数 を参照䞋さい。
That means that you can write things like this:
PHPの配列型は非垞に解りにくいため、ここで、配列の匷力な機胜を瀺す いく぀かの䟋を玹介したす。
?php $error_descriptions[ 1] = "A fatal error has occured"; $error_descriptions[2] = "PHP issued a warning"; $error_descriptions[8] = "This is just an informal notice";?
䟋 7-4array()の䜿甚䟋
It works, because bar is due to its syntax expected to be a constant expression.
䟋 7-5コレクション
At some point in the future, the PHP team might want to add another constant or keyword, or you may introduce another constant into your application, and then you get in trouble.
配列の倀をこのようなルヌプで盎接倉曎するこずはできないこずに泚意 しお䞋さい。 これを解決するには、次のようにしたす。
Note:
䟋 7-6コレクション
See the above examples for details on why as well as the section on variable parsing in strings.
この䟋は、1から始たる配列を䜜成したす。
If you convert an object If you convert an object to an array, you get the properties (member variables) of that object as the array's elements.
䟋 7-71から始たる添字
Array ([0] = RED [1] = BLUE [2] = GREEN [3] = YELLOW) * /?
配列には順番が付けられたす。異なった゜ヌト関数を甚いお順番を倉曎 するこずも可胜です。より詳现な情報に぀いおは、 配列関数 を参照䞋さい。
Array ([1] = 'January '[2] = 'February' [3] = 'March ') * /
䟋 7-9配列の゜ヌト
Arrays are ordered.
配列の倀は䜕でも良いため、その倀を他の配列ずするこずも可胜です。 これにより、再垰的な配列や倚次元の配列を䜜成するこずが可胜です。
?php $arr1 = array( 2, 3); $arr2 = $arr1; $arr2[] = 4; / / $arr2 is changed, / / $arr1 is still array(2,3) $arr3 = $arr1; $arr3[] = 4; / / now $arr1 and $arr3 are the same?
䟋 7-10再垰および倚次元配列
A boolean A boolean expresses a truth value.
論理型は、最も簡単な型です。 boolean は、真停の倀を衚 したす。この倀は、 TRUE たたは FALSE のどちらかになりたす。
Note:
泚意 boolean型は、PHP 4で導入されたした。
To specify a boolean literal, use either the keyword TRUE or FALSE.
booleanリテラルを指定するには、キヌワヌド TRUE たたは FALSE を指定しお䞋さい。䞡方ずも倧文字小 文字に䟝存したせん。
Usually you use some kind of operator which returns a boolean value, and then pass it on to a control structure.
通垞、 boolean 型の倀を返す 挔算子 を䜿甚しおから、 制埡構造 にその結果を枡 したす。
To explicitly convert a value to boolean, use either the (bool) or the (boolean) cast.
boolean に明瀺的に倉換を行うには、キャスト (bool) たたは (boolean) を 䜿甚したす。しかし、挔算子、関数、制埡構造が boolean 型の匕数を必芁ずする堎合には、倀は自動的に倉換されるため、倚くの 堎合、キャストは䞍芁です。
However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires a boolean argument.
型の盞互倉換 も参照䞋さい。
When converting to boolean, the following values are considered FALSE:
boolean に倉換する堎合、次の倀は FALSE ずみなされたす。
the integer 0 (zero)
boolean の FALSE
the empty string, and the string "0"
integer の 0 (れ ロ)
an object with zero member variables
float の 0.0 (れロ)
Warning
空の 文字列 、 および 文字列 の "0"
Home
れロを芁玠ずする オブゞェ クト
Types
特別な倀 NULL (倀がセット されおいない倉数を含む)
Integers
-1 は、他のれロでない数を同様に(正負によら ず) TRUE ずみなされたす。
?php $a = 1.234; $b = 1.2e3; $c = 7E-10;?
("float","double","実数"のような) フロヌト数は、次の構文により指定 できたす。
This can lead to confusing results: for example, floor( (0.1+0.7)*10) will usually return 7 instead of the expected 8 as the result of the internal representation really being something like 7.9999999999....
0.1 や 0.7 のような 簡単な小数衚珟も若干粟床を倱うこずなく内郚的な2進衚珟に倉 換するこずはできたせん。これにより、混乱する結果を生じるこずがあ りたす。぀たり、 floor((0.1+0.7)*10) は 予想される 8 の代わりに実際の内郚衚珟の結果ずし お 7.9999999999... のようなものを結果ずしお返し たす。
If you really need higher precision, you should use the arbitrary precision math functions or gmp functions instead.
これは、いく぀かの分数は有限の桁数の小数点衚蚘で正確に衚珟できな いずいう事実に関係しおいたす。䟋えば、 1/3 の小 数点衚蚘は、 0.3333333... ずなりたす。
For values of other types, the conversion is the same as if the value would have been converted to integer and then to float.
よっお、小数の最埌の桁を信甚しおはいかたせんし、小数が等しいずい う比范を行っおはいけたせん。より高い粟床が必芁な堎合には、 任意粟床数孊関数 たたは gmp 関数を代わりに䜿甚しお䞋さい。
Prev
PHPは、8皮類の基本型をサポヌトしたす。
PHP supports eight primitive types.
4皮類のスカラヌ型:
Four scalar types:
論理倀(boolean)
integer
敎数(integer)
floating-point number (float)
浮動小数点数(float)
array
文字列(string)
object
配列(array)
NULL
オブゞェクト(object)
number
リ゜ヌス(resource)
callback
ヌル(NULL)
Note:
泚意 このマニュアルには、しばしば mixed ずいうパラ メヌタが珟れたす。この疑䌌的な型は、そのパラメヌタに関しお耇数の 型が䜿甚可胜であるこずを瀺したす。
Note:
倉数の型は、基本的にプログラマによりセットされたせん。むしろ、その倉 数が䜿甚される文の内容に応じおPHPにより実行時に決定されたす。
To check for a certain type, do not use gettype(), but use the is_ type functions.
泚意 もし 匏 の型ず倀を正確に 知りたい堎合は、 var_dump() 関数を䜿甚しおください。
If you would like to force a variable to be converted to a certain type, you may either cast the variable or use the settype() function on it.
ある倉数の型を匷制的に他の型に倉換したい堎合、倉数を キャスト するか、 settype() 関数を䜿甚したす。
For more information, see the section on Type Juggling.
倉数は、その型に䟝存しお異なった動䜜をする堎合があるこずに 泚意しおください。詳现な情報に぀いおは、 型の倉換 のセ クションを参照䞋さい。
An integer is a number of the set Z = {..., -2, -1, 0, 1, 2,...}.
integer は、Z = {..., -2, -1, 0, 1, 2, ...}ずいう集合 です。
Arbitrary length integers and Floating point numbers
任意粟床敎数 および float も参照䞋さい。