NFicano Posted April 6, 2008 Share Posted April 6, 2008 I wanted to build custom classes to divide up and organize my applications functionality. I'm using PHP PEAR's liveUser and MDB2 packages. Now normally, to interact with liveUser, you must use require_once to point to the config file (a file that stores several object instances, configuration preferences etc). For example, to update the current users password: require_once '../../sys/conf.php'; // check if a user is logged in if (!$LU->isLoggedIn()) { // path to login form include_once '../../sys/login.php'; // exit script exit(); } // get username $handle = $LU->getProperty('handle'); $filter = array('container' => 'auth','filters' => array('handle' => $handle)); // get user id $user_id = $LUA->getUsers($filter); $data = array('passwd' => 'new_password'); $updatedUser = $LUA->updateUser($data, $user_id[0]['perm_user_id']); now if I wanted to divide up and group similar functionality into classes, how would I interact with the instances declared in the configuration file? Whenever I try to build a class with multiple functions such as: require_once '/sys/conf.php'; // check if a user is logged in if (!$LU->isLoggedIn()) { // path to login form include_once '/sys/login.php'; // exit script exit(); } class mgmt { function new_passwd($new_passwd) { // get username $handle = $LU->getProperty('handle'); $filter = array('container' => 'auth','filters' => array('handle' => $handle)); // get user id $user_id = $LUA->getUsers($filter); $data = array('passwd' => $new_passwd); $updatedUser = $LUA->updateUser($data, $user_id[0]['perm_user_id']); } function change_name($new_name) { // get username $handle = $LU->getProperty('handle'); $filter = array('container' => 'auth','filters' => array('handle' => $handle)); // get user id $user_id = $LUA->getUsers($filter); $data = array('passwd' => $new_name); $updatedUser = $LUA->updateUser($data, $user_id[0]['perm_user_id']); } } $a = new mgmt; $a->new_passwd("test123"); $a->change_name("Joe"); I get: "Notice: Undefined variable: LU" and Call to a member function getProperty() on a non-object Link to comment https://forums.phpfreaks.com/topic/99886-creating-custom-classes/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.