Skip to content

Commit dae5562

Browse files
committed
add : add php @throws demo
1 parent f80aed5 commit dae5562

File tree

7 files changed

+41
-66
lines changed

7 files changed

+41
-66
lines changed

php/deprecated/index.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TagDeprecated
1212
*
1313
* @deprecated
1414
*/
15-
static public function willBeDeprecated()
15+
public static function willBeDeprecated()
1616
{
1717
}
1818

@@ -21,7 +21,7 @@ static public function willBeDeprecated()
2121
*
2222
* @deprecated 1.0.0
2323
*/
24-
static public function willBeDeprecatedNextVersion()
24+
public static function willBeDeprecatedNextVersion()
2525
{
2626
}
2727

@@ -31,14 +31,14 @@ static public function willBeDeprecatedNextVersion()
3131
* @see TagDeprecated::apiV2()
3232
* @deprecated 3.0.0 此方法以被废弃,请使用最新方法v2
3333
*/
34-
static public function apiV1()
34+
public static function apiV1()
3535
{
3636
}
3737

3838
/**
3939
* V1已经过时了,我就是最靓的V2方法
4040
*/
41-
static public function apiV2()
41+
public static function apiV2()
4242
{
4343
}
4444
}

php/example/index.php

-38
This file was deleted.

php/param/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TagParam
1313
* @param string $piece 碎片
1414
* @return string[]
1515
*/
16-
static public function join($collection, $piece)
16+
public static function join($collection, $piece)
1717
{
1818
$collection[] = $piece;
1919

php/throws/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@throws
2+
=======
3+
4+
`@throws` : 抛出一个异常,告诉调用方需要做好处理异常相关工作.
5+
6+
**此标签推荐使用PhpStorm进行阅读,可以能直观体现标签的作用**
7+
8+
语法
9+
=======
10+
11+
> `@throws [Type] [<description>]`
12+
13+
14+
标签效果
15+
=======
16+
17+
![demo.jpg](./docs/demo.png)

php/throws/docs/demo.png

69.9 KB
Loading

php/throws/index.php

+17-21
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
<?php
22

3-
class BeiException extends Exception {}
4-
class HuException extends Exception {}
5-
6-
class ClassForThrows
3+
/**
4+
* <p>"@throws" : 抛出一个异常,告诉调用方需要做好处理异常相关工作</p>
5+
*
6+
* <b>此标签建议在PHPStorm中打开此演示文档,可以看到具体的标签效果</b>
7+
*/
8+
class TagThrows
79
{
810
/**
9-
* @throws BeiException
11+
* 整数相除
12+
*
13+
* @param integer $a
14+
* @param integer $b
15+
* @return float|int
16+
* @throws \Exception 被除数不能为0
1017
*/
11-
public static function throwBeiException()
18+
public static function div($a, $b)
1219
{
13-
throw new BeiException();
14-
}
15-
16-
/**
17-
* @param boolean $type
18-
* @throws BeiException|HuException
19-
*/
20-
public static function throwMixedException($type)
21-
{
22-
if ($type) {
23-
throw new BeiException();
20+
if (empty($b)) {
21+
throw new Exception('Division by zero');
2422
}
2523

26-
throw new HuException();
24+
return $a / $b;
2725
}
2826
}
2927

30-
ClassForThrows::throwBeiException();
31-
32-
ClassForThrows::throwMixedException(true);
28+
echo TagThrows::div(1, 2);

php/var/index.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class TagVar
1111
/**
1212
* <1>.第一种使用方法,只定义类型,通常用于类成员变量中
1313
*
14-
* @var array 标签数组
14+
* @var array|null 标签数组
1515
*/
16-
public $tags;
16+
public $tags = null;
1717
}
1818

1919
$tag = new TagVar();

0 commit comments

Comments
 (0)