Heim  >  Artikel  >  Backend-Entwicklung  >  关于include的变量运用

关于include的变量运用

WBOY
WBOYOriginal
2016-06-13 11:11:001197Durchsuche

关于include的变量使用
有2个文件:
1、index.php
2、index.controller.php
在index.php 里面声明了一个变量 $method;
在index.php 里面 include 了 index.controller.php.
请问在index.controller.php 里面 class index_controller类里面的方法 如何使用$method
我是判断该方法在不在。
index.php Code:

<br />$method = show;<br />


index.controller.php Code: 
<br />class index_controller {<br /> function __construct()<br /> {<br />    if(!method_exists($this,$method)){<br />	exit("不存在的方法");<br />    } <br /> }<br />}<br />


------解决方案--------------------
构造函数中获取不到$method的值,申明global 或者传递进去。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn