Genesis730 Posted October 2, 2010 Share Posted October 2, 2010 So I have this code that generates a random ID class Session { var $username; //Username given on sign-up var $userid; //Random value generated on current login ... ... function Session(){ $this->time = time(); $this->startSession(); } ... ... $this->userid = $_SESSION['userid'] = $this->generateRandID(); ... ... function generateRandID(){ return md5($this->generateRandStr(16)); } and when it runs i get this error... Fatal error: Call to undefined method Session::generateRandID() Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/215012-fatal-error-call-to-undefined-method/ Share on other sites More sharing options...
trq Posted October 2, 2010 Share Posted October 2, 2010 Can we see your actual code and where you are calling this method? ps: Forming a construct by naming a method the same as the class has been deprecated since php 5. Quote Link to comment https://forums.phpfreaks.com/topic/215012-fatal-error-call-to-undefined-method/#findComment-1118439 Share on other sites More sharing options...
Genesis730 Posted October 5, 2010 Author Share Posted October 5, 2010 The session is called everytime a webpage is called, it's part of session.php which is included at the top of each page. That is the only code that references generateRandID other than updating it to the database. And if forming a construct by naming a method the same as the class has been deprecated since php 5, what would be an example of how properly code what i am attempting? Quote Link to comment https://forums.phpfreaks.com/topic/215012-fatal-error-call-to-undefined-method/#findComment-1119135 Share on other sites More sharing options...
trq Posted October 5, 2010 Share Posted October 5, 2010 The session is called everytime a webpage is called, it's part of session.php which is included at the top of each page. That is the only code that references generateRandID other than updating it to the database. Well, without seeing that relevant code we can't help anymore except to reiterate what the error says which is that the generateRandID() method is not part of the Session object. And if forming a construct by naming a method the same as the class has been deprecated since php 5, what would be an example of how properly code what i am attempting? Instead of.... function Session() { .... } You would use.... function __construct() { ... } Quote Link to comment https://forums.phpfreaks.com/topic/215012-fatal-error-call-to-undefined-method/#findComment-1119146 Share on other sites More sharing options...
phpchamps Posted October 5, 2010 Share Posted October 5, 2010 working perfectly for me... <?php class Session { var $username; //Username given on sign-up var $userid; //Random value generated on current login function Session(){ $this->time = time(); $this->startSession(); $this->userid = $_SESSION['userid'] = $this->generateRandID(); } function startSession(){ echo "AAA"; } function generateRandStr(){ echo rand(0,49); } function generateRandID(){ return md5($this->generateRandStr(16)); } } $obj = new Session(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/215012-fatal-error-call-to-undefined-method/#findComment-1119243 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.