Jump to content

Fatal Error: Call to undefined method


Genesis730

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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() {
  ...
}

Link to comment
Share on other sites

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();
   ?>
   
  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.