ethanhann / redis-raw-php

MIT License
5 stars 8 forks source link

Error: Typed property Ehann\RedisRaw\AbstractRedisRawClient::$logger must not be accessed before initialization AbstractRedisRawClient.php:40 #4

Open uweng opened 8 months ago

uweng commented 8 months ago

Using "redisearch-php" with this code :

<?php
require_once 'vendor/autoload.php';
use Ehann\RedisRaw\PhpRedisAdapter;
use Ehann\RediSearch\Index;

$redis = new PhpRedisAdapter();
$index = new Index($redis);

//Connecting to Redis server on localhost
 try
   {
     $redis->connect('127.0.0.1', 6379);
     echo "Successfull connect to Redis-Server!\n";
   } catch (Exception $e)
   {
     echo "Error connect to Redis-Server!\n";
   }
//Create Index if not allready exist
 try
   {
     $index->addTextField('sessionId')
          ->addTextField('timestamp')
          ->create();
     echo "Index 'logging' created!\n";
    } catch (Exception $e)
    {
      echo "Error create Index 'logging' !\n";
    }'

results in: $ php ./bug.php

Successfull connect to Redis-Server!
PHP Fatal error:  Uncaught Error: Typed property Ehann\RedisRaw\AbstractRedisRawClient::$logger must not be accessed before initialization in /logging/vendor/ethanhann/redis-raw/src/AbstractRedisRawClient.php:40
Stack trace:
#0 /logging/vendor/ethanhann/redis-raw/src/PhpRedisAdapter.php(39): Ehann\RedisRaw\AbstractRedisRawClient->prepareRawCommandArguments('FT.CREATE', Array)
#1 /logging/vendor/ethanhann/redisearch-php/src/RediSearchRedisClient.php(109): Ehann\RedisRaw\PhpRedisAdapter->rawCommand('FT.CREATE', Array)
#2 /logging/vendor/ethanhann/redisearch-php/src/AbstractRediSearchClientAdapter.php(24): Ehann\RediSearch\RediSearchRedisClient->rawCommand('FT.CREATE', Array)
#3 /logging/vendor/ethanhann/redisearch-php/src/Index.php(75): Ehann\RediSearch\AbstractRediSearchClientAdapter->rawCommand('FT.CREATE', Array)
#4 /logging/bug.php(23): Ehann\RediSearch\Index->create()
#5 {main}
  thrown in /logging/vendor/ethanhann/redis-raw/src/AbstractRedisRawClient.php on line 40
uweng commented 8 months ago

The fix like this in File AbstractRedisRawClient.php:


-- protected LoggerInterface $logger;
++private $logger;
++
++ public function __construct(LoggerInterface $logger = null)
++  {
++        $this->logger = $logger;
++   }
works fine. 
cirolosapio-accenture commented 3 months ago

+1

if I require ethanhann/redis-raw composer installs the version 2.1.0 but in this repository the latest version is 2.0.0 and it hasn't this bug