0

I have a issue trying to save an object into session.

From my index.php I create the object and store it into session:

  include_once __DIR__.'/vendor/autoload.php';
  use Axiom\Rivescript\Rivescript;
  $test = new Rivescript();
  $test->load(realpath(__KNOWLEDGE__));

  session_start();
  if (isset($_SESSION['ENGINE'])){
    unset($_SESSION['ENGINE']);
  }
  $_SESSION['ENGINE'] = $test;

in another php page I recall the session to get te object:

session_start();
if (!isset($_SESSION['ENGINE'] )){
    // error
}else{
    $test = $_SESSION['ENGINE'];
    $txt = $test->reply($input,$client_id);
}

This page is called by AJAX.

and I get this error:

Notice: Trying to get property 'memory' of non-object in /var/www/html/vendor/axiom/rivescript/src/Cortex/Input.php on line 64

Fatal error: Uncaught Error: Call to a member function substitute() on null in /var/www/html/vendor/axiom/rivescript/src/Cortex/Input.php:64 Stack trace: #0 /var/www/html/vendor/axiom/rivescript/src/Cortex/Input.php(33): Axiom\Rivescript\Cortex\Input->cleanOriginalSource() #1 /var/www/html/vendor/axiom/rivescript/src/Rivescript.php(34): Axiom\Rivescript\Cortex\Input->__construct('ciao', '5e5fe0688782a') #2 /var/www/html/include/bot.php(24): Axiom\Rivescript\Rivescript->reply('ciao', '5e5fe0688782a') #3 {main} thrown in /var/www/html/vendor/axiom/rivescript/src/Cortex/Input.php on line 64

Any help ??

  • Because reply is a function of Rivescript class. – Simone Rossaini Mar 05 '20 at 10:32
  • I dont get it, I would like to store the whole Rivescript object into session, "functions" included, is this possible in php? – user3830758 Mar 05 '20 at 10:38
  • Try in the first page session start at the first line then try again – Simone Rossaini Mar 05 '20 at 11:59
  • I tried nothing chaged. If I put session_start() at the beginning of the second page also, I got another error: Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Axiom\Rivescript\Rivescript" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide an autoloader to load the class definition in /var/www/html/include/bot.php on line 29 – user3830758 Mar 05 '20 at 13:42
  • Just for example why don't use autoload in a function and call that in all page? – Simone Rossaini Mar 05 '20 at 13:44
  • The point is that the class Rivescript has some kind of memory and I cannot instantiate that class in every page because I am losing that memory. That class is not written by me. – user3830758 Mar 05 '20 at 13:52

0 Answers0