Home > Backend Development > PHP Tutorial > 关于include的变量运用

关于include的变量运用

WBOY
Release: 2016-06-13 12:57:06
Original
1059 people have browsed it

关于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 />
Copy after login


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


------解决方案--------------------
构造函数中获取不到$method的值,申明global 或者传递进去。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template