Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Needs PHP 8 support #326

Closed
cmp-nct opened this issue Feb 28, 2021 · 8 comments · Fixed by #341
Closed

Needs PHP 8 support #326

cmp-nct opened this issue Feb 28, 2021 · 8 comments · Fixed by #341

Comments

@cmp-nct
Copy link

cmp-nct commented Feb 28, 2021

Title

  • bug: Deprecated: Required parameter $callback follows optional parameter $interval in /binance/vendor/jaggedsoft/php-binance-api/php-binance-api.php on line 2009

Short Description:
The Api does not support the current PHP version.
I've no idea how big the scope of the problem is, the first deprecated warnings appear quite early
I believe this needs a full evaluation to bring the API up to date, without PHP 8 support it's destined to die

php version:

  • 8.0
@cmp-nct cmp-nct changed the title No PHP 8 support Needs PHP 8 support Feb 28, 2021
@dmzoneill dmzoneill self-assigned this Mar 10, 2021
@dmzoneill
Copy link
Collaborator

hi Compunect,

I'm running php 8.0.3.
I'm yet to see any errors.
Could you provide examples of said issues.
Without any detailed reports, its hard to move this forward.

thank you

dmzoneill@dave-x1e2:~/src/php-binance-bot$ php --version
PHP 8.0.3 (cli) (built: Mar 10 2021 13:42:09) ( ZTS DEBUG )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies

@Antonsteb
Copy link

Antonsteb commented Mar 14, 2021

Hi, I ran the same error in laravle cron
Kernal:
protected function schedule(Schedule $schedule) { $binanceService = new BinanceService($key, $secret); $schedule->call( $binanceService)->everyMinute(); }

BinanceService:
`class BinanceService
{
private $apiKey;
private $apiSecret;

public function __construct($apiKey,$apiSecret)
{
    $this->apiKey = $apiKey;
    $this->apiSecret = $apiSecret;

}

/**
 * @return AlgorithmEventDto[] array of algorithm events
 * @throws Exception
 */
public function runAlgorithm(): array
{
    $api = new Binance\API($this->apiKey, $this->apiSecret);   // in this string i get this error     

}

/**
 * for crone.
 */
public function __invoke()
{
    try {
       $this->runAlgorithm();
    } catch (Exception $e) {
        file_put_contents($this->errorPath,$e->getMessage(),FILE_APPEND);
    }
}    

}`

I only get this error when running through cron.
If I do in Controller:
$binanceService = new BinanceService ($key, $secret);
$binanceService();
then there is no error.

php version: 8.0.3

@jianjye
Copy link

jianjye commented Mar 20, 2021

This issue should be related to this: https://stackoverflow.com/questions/65297279/required-parameter-xxx-follows-optional-parameter-yyy

public function chart($symbols, string $interval = "30m", callable $callback, $limit = 500) {}

Since $callback is not optional, it needs to be in front of $interval in PHP 8. Either that or we need to add a default to $callback to continue on this argument sequence.

@jianjye
Copy link

jianjye commented Mar 20, 2021

I have also encountered this error:

 ErrorException 

  uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero

  at vendor/jaggedsoft/php-binance-api/php-binance-api.php:1268
    1264▕         }
    1265▕         if (is_array($priceData)) {
    1266▕             uasort($balances, function ($opA, $opB) {
    1267▕                 return $opA['btcValue'] < $opB['btcValue'];
  ➜ 1268▕             });
    1269▕             $this->btc_value = $btc_value;
    1270▕             $this->btc_total = $btc_total;
    1271▕         }
    1272▕         return $balances;

The correct update should be to replace

Replace line 1267:
return $opA['btcValue'] < $opB['btcValue'];

With:
return ($opA['btcValue'] < $opB['btcValue']) ? -1 : 1;

@dmzoneill
Copy link
Collaborator

this should be resolved by

#342

@dmzoneill dmzoneill linked a pull request Mar 27, 2021 that will close this issue
@dmzoneill dmzoneill removed the invalid label Mar 27, 2021
@ePascalC
Copy link
Collaborator

ePascalC commented Apr 4, 2021

@dmzoneill I suppose that is 341 and not 342? For the 2nd PHP item from @jianjye , do you want to split it into another issue?

@jianjye Should it not return 0 and 1? According to https://www.php.net/manual/en/language.types.boolean.php -1 results in true! Or better, should it not be ? false : true to be more clear? (Haven't checked PHP 8 yet...)

@jianjye
Copy link

jianjye commented Apr 4, 2021

@ePascalC The uasort function would return boolean, but in its callback function it expects 0 (if equals), -1 or 1 if one is greater than another based on the doc's example: https://www.php.net/manual/en/function.uasort. Caveat: I have not used this function personally myself.

Sure we can separate this as a different issue.

@ePascalC
Copy link
Collaborator

ePascalC commented Apr 5, 2021

@jianjye ah of course, you are right! Let me push that in. Thx.

dmzoneill pushed a commit that referenced this issue Apr 5, 2021
mxgrim pushed a commit to mxgrim/php-binance-api that referenced this issue Apr 20, 2021
@ePascalC ePascalC closed this as completed Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants