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
https://forums.phpfreaks.com/topic/215012-fatal-error-call-to-undefined-method/
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?

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.