以下のようなヘルパーメソッド(?)を使う、などいかがでしょうか?
PHP5.6以上なら、可変長引数リストで実装できそうです。
http://php.net/manual/ja/functions.arguments.php#functions.variable-arg-list
php
1function instanceOneOfThem() {
2 $parameters = func_get_args();
3 if (sizeof($parameters) <= 1) {
4 throw new RangeException('Too few arguments.');
5 }
6
7 $object = array_shift($parameters);
8 foreach ($parameters as $type) {
9 if ($object instanceof $type) {
10 return true;
11 }
12 }
13
14 return false;
15}
使用例
php
1error_reporting(E_ALL);
2
3try {
4
5 throw new PDOException();
6// throw new RuntimeException();
7// throw new InvalidArgumentException();
8// throw new Exception();
9
10} catch (Exception $e) {
11
12 if (instanceOneOfThem($e, 'PDOException', 'RuntimeException')) {
13 print 'Is instance!';
14 } else {
15 print 'Is not instance..';
16 }
17
18}
19
20function instanceOneOfThem() {
21 $parameters = func_get_args();
22 if (sizeof($parameters) <= 1) {
23 throw new RangeException('Too few arguments.');
24 }
25
26 $object = array_shift($parameters);
27 foreach ($parameters as $type) {
28 if ($object instanceof $type) {
29 return true;
30 }
31 }
32
33 return false;
34}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。