我正在为我的新网站建立一个用户类,但是这次我想要以不同的方式构建它...
我知道C++,Java甚至Ruby(可能还有其他编程语言)允许在主类中使用嵌套/内部类,这样可以使代码更加面向对象和组织.
在PHP中,我想做这样的事情:
<?php
public class User {
public $userid;
public $username;
private $password;
public class UserProfile {
// Some code here
}
private class UserHistory {
// Some code here
}
}
?>
Run Code Online (Sandbox Code Playgroud)
这可能在PHP?我怎样才能实现它?
UPDATE
如果不可能,未来的PHP版本是否可能支持嵌套类?
在这里得到一个非常奇怪的错误,我正在写一个flatfile数据库类,这一切都正常,直到我刷新,现在我不断得到这个消息:
致命错误:在第50行的/home/reithg/public_html/test/engine/class.database.php中调用非对象上的成员函数name()
我打电话给班级如下:
<?php
ini_set('display_errors', '1');
require('engine/class.database.php');
$config = new Config("lessons", array('first', 'second', 'third', 'fourth'), "data/");
$db = new Database($config, true);
print("Querying DB for 'theta' no exclusions: <br />");
print_r($db->query('theta', NULL, NULL));
print("<p /> Querying DB for 'theta' in column 'second': <br />");
print_r($db->query('theta', 'second', NULL));
print("<p /> Querying DB for first two rows: <br />");
print_r($db->getRows(2));
print("<p /> Querying DB for last three rows: <br />");
print_r($db->getRows(3, true));
print("<p /> Cleaning data …
Run Code Online (Sandbox Code Playgroud)