3

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?

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

7 Comments

Replacing \Sodium\library_version_major() with sodium_library_version_major() results in the same error.
Bad example since that one was replaced with the SODIUM_LIBRARY_MAJOR_VERSION constant. But actual functions now have a sodium_ prefix.
I also got problems with it, thanks for the answer. Is there an official documentation for those new functions? Apparently they change more function names, since I cannot access sodium_crypto_pwhash_scryptsalsa208sha256_str(). On the libsodium website I can see only outdated examples.
crypto_pwhash_scryptsalsa208sha256_str() doesn't exist any more. It doesn't exist any longer in minimal builds of libsodium either, since there has been a high-level crypto_pwhash() API for a long time now. So, use sodium_crypto_pwhash(), sodium_crypto_pwhash_str() and sodium_crypto_pwhash_str_verify().
I did the same thing, and it's enabled in phpinfo(). But sodium_library_version_major() still get the same error.
|
3

For those who installed Pecl Version of Soidum and Enabled it in php.ini (extension=sodium.so) And Have same error like Call to Undefined ...

After Restarting Apache & nginx and lack of success finally Reboot server get sodium work exteremly.

PHP 7.3 & >7.3 = libsodium 2.1

Hope to be helpful.

Comments

3

For those who couldnt get the answer working.. thats because it should be:

<?php
var_dump([
    SODIUM_LIBRARY_MAJOR_VERSION,
    SODIUM_LIBRARY_MINOR_VERSION,
    SODIUM_LIBRARY_VERSION
]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.