{"id":565,"title":"php\u8bbe\u8ba1\u6a21\u5f0f-\u804c\u8d23\u94fe\u6a21\u5f0f\u53ca\u5e94\u7528\u573a\u666f\u4e3e\u4f8b","good":0,"bad":0,"hit":975,"created_at":"2023-01-19 04:36:57","content":"
<?php<\/p>
<\/p>
\/**<\/p>
* \u804c\u8d23\u94fe\u6a21\u5f0f\uff1a\u9002\u5e94\u4e8e\u94fe\u5f0f\u6743\u9650<\/p>
* \u4e3a\u4ec0\u4e48\u8fd9\u6837\u5904\u7406\u5462\uff0c\u5982\u679c\u7528\u4f20\u7edf\u7684if else\u6216switch\u4e5f\u53ef\u4ee5\u5904\u7406\uff0c\u4f46\u662f\u5982\u679c\u589e\u52a0\u4e86N\u79cd<\/p>
* \u53c8\u5f97\u53bb\u6539\u539f\u6765\u7684\u4ee3\u7801\uff0c\u4e0d\u5229\u4e8e\u6269\u5c55\uff0c\u8fd9\u91cc\u6bcf\u4e2a\u7c7b\u90fd\u5b58\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u6b64\u5904\u4e3a\u4e86\u65b9\u4fbf\u5c55\u793a\u90fd\u5199\u5728\u4e00\u4e2a\u6587\u4ef6\u91cc\u4e86<\/p>
* \u8fd9\u6837\u7684\u8bdd\u5982\u679c\u4e2d\u95f4\u65b0\u589e\u4e86\u6b65\u9aa4\uff0c\u53ea\u9700\u6c42\u65b0\u65b0\u5efa\u4e00\u4e2a\u7c7b\u6587\u4ef6\u5373\u53ef,\u8fd9\u6837\u5c31\u53ef\u4ee5\u4e0d\u6539\u539f\u6765\u6216\u5c11\u6539\u539f\u6765\u7684\u4ee3\u7801<\/p>
* \u4ee5\u8fbe\u5230\u7075\u6d3b\u6269\u5c55\u7684\u76ee\u7684<\/p>
*\/<\/p>
class board<\/p>
{<\/p>
protected $power = 1;\/\/\u6743\u9650<\/p>
protected $top = 'admin';\/\/\u4e0a\u7ea7<\/p>
<\/p>
public function process($power)<\/p>
{<\/p>
if ($power <= $this->power) {<\/p>
echo "\u7248\u4e3b\u5904\u7406<br\/>";<\/p>
} else {<\/p>
$top = new $this->top;<\/p>
$top->process($power);<\/p>
}<\/p>
}<\/p>
}<\/p>
<\/p>
class admin<\/p>
{<\/p>
protected $power = 2;<\/p>
protected $top = '';<\/p>
<\/p>
public function process($power)<\/p>
{<\/p>
if ($power <= $this->power) {<\/p>
echo "\u7ba1\u7406\u5458\u5904\u7406<br\/>";<\/p>
} else {<\/p>
$top = new $this->top;<\/p>
$top->process($power);<\/p>
}<\/p>
}<\/p>
}<\/p>
\/\/\u5047\u8bbe\u67d0\u7528\u6237\u53d1\u4e86\u4e00\u4e2a\u5e16\u5b50\uff0c\u5148\u4ea4\u7ed9\u7248\u4e3b\u5904\u7406\uff0c\u5982\u679c\u6743\u9650\u4e0d\u591f\u5f15\u4eba\u6ce8\u76ee\u7ba1\u7406\u5458\u5904\u7406<\/p>
$user = new board();<\/p>
$user->process(1);<\/p>
$user->process(2);<\/p>
<\/p>
\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>
<\/span>\u7248\u4e3b\u5904\u7406<\/span>
\u7ba1\u7406\u5458\u5904\u7406<\/span><\/span><\/p>
<\/p>"}