2

I'm trying to understand -> https://www.php.net/manual/en/function.openssl-sign.php which has &$signature parameter. I read this -> PHP &$string - What does this mean? but still don't understand why must we have &$signature as a parameter or how do we use it. The examples at https://www.php.net did not describe the use of that variable.

Here's one of their examples.

<?php
// $data is assumed to contain the data to be signed

// fetch private key from file and ready it
$pkeyid = openssl_pkey_get_private("file://src/openssl-0.9.6/demos/sign/key.pem");

// compute signature
openssl_sign($data, $signature, $pkeyid);

// free the key from memory
openssl_free_key($pkeyid);
?>

Btw, have a fabulous coding new year 2022!

ratib90486
  • 89
  • 1
  • 7

2 Answers2

0

Function 'openssl_sign' is defined to computes a signature which is passed by reference.

Without '&', parameter signature won't change after the function is called.

Robert
  • 63
  • 9
0

If you pass vars by reference to a function so the function can modify the variable directly without returning value.

https://www.php.net/manual/en/language.references.pass.php

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79