Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libsodium "Call to undefined function" error

I have installed libsodium and libsodium-php on ubuntu 16.04 but when I run:

`<?php
var_dump([
    \Sodium\library_version_major(),
    \Sodium\library_version_minor(),
    \Sodium\version_string()
]);`

I get an error saying:

PHP Fatal error:  Uncaught Error: Call to undefined function Sodium\library_version_major() 

According to phpinfo() Sodium is enabled and the compiled version is 2.0.1 and the library version is 1.0.13. What am I doing wrong?

like image 843
T. Doe Avatar asked Aug 05 '26 19:08

T. Doe


1 Answers

The PHP API for libsodium has changed in version 2.0.0 of the extension.

Originally, all functions were in a \Sodium\ namespace.

However, following a vote by PHP developers regarding its inclusion in PHP 7.2, it was decided to move everything to the global namespace instead.

So, what used to be \Sodium\library_version_major() is now sodium_library_version_major().

like image 133
Frank Denis Avatar answered Aug 08 '26 10:08

Frank Denis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!