1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

関数エイリアス

Last updated at Posted at 2013-12-17

文字列から1文字を見つけてみます。

if (strchr('abcde', 'c')) echo 'c 見つけた';

しかし、よく考えると、PHPには1文字を表す型は無かったのでは?

if (strchr('abcde', 'bcd')) echo 'bcd 見つけた';

これでも正常に見つかります。関数名と挙動が一致していません。

どうやら、strchr関数はstrstr関数の別名らしいのです。
これを 関数エイリアス と言います。

どちらの関数を呼び出しても、全く同じ機能を提供します。

関数エイリアスのリスト

詳しくはhttp://php.net/manual/ja/aliases.php

個人的に混乱しやすいものを以下にまとめます。

エイリアス名 元の関数名
strchr strstr
fputs fwrite
die exit
join implode
chop rtrim
is_double is_float
is_long is_int
sizeof count

他の言語から移行してきた方は注意が必要かも?

注意点

  • fputs関数とfwrite関数は同じ関数ですが、fgets関数とfread関数は別の関数です。fgets関数は一行、fread関数は指定したバイト数を読み込みます。
  • join関数とimplode関数は同じ関数ですが、split関数とexplode関数は別の関数です。split関数は区切り文字に正規表現が使えます。explode関数は正規表現は使えませんが高速です。PHP 5.3.0 以降はsplit関数は非推奨となりましたので、preg_split関数を使いましょう。
  • echoとprintは別の言語構造です(どちらも関数ではありません)。挙動が微妙に違いますが、あまり意識する必要はないでしょう。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?