php类的简单问题
class db{
private $host;
private $user;
private $pwd;
private $db;
function connect($host,$user,$pwd,$db)
{
..........
}
}
假如说我在另一个文件假设名为abc.php里引入这个类,在生成对象的时候这样写:$db=new db("192.168.1.11","zhangsan","1234","test");括号里的参数是怎么个用法?是类里所有方法都可以用吗?跪求详细解答!!!
------解决方案--------------------
实例参数会首先传递给类的构造方法,构造方法再传递给类的属性或者方法
class db{ private $host; private $user; private $pwd; private $db; public function __construct($host,$user,$pwd,$db){ $this->connect($host,$user,$pwd,$db); } public function connect($host,$user,$pwd,$db){ //.... }}<br><font color="#e78608">------解决方案--------------------</font><br>正解,要 有个构造函数<br>
$obj = new db();$obj->db("192.168.1.11","zhangsan","1234","test");<br><font color="#e78608">------解决方案--------------------</font><br>LS的给力啊!一次来2个!<br>有实力的话实习机会很好找的!!<div class="clear"> </div>