1
0
mirror of https://github.com/php/php-src.git synced 2026-04-18 05:21:02 +02:00
Files
archived-php-src/ext/openssl/tests/openssl_x509_export_basic.phpt
Nikita Popov b10416a652 Deprecate passing null to non-nullable arg of internal function
This deprecates passing null to non-nullable scale arguments of
internal functions, with the eventual goal of making the behavior
consistent with userland functions, where null is never accepted
for non-nullable arguments.

This change is expected to cause quite a lot of fallout. In most
cases, calling code should be adjusted to avoid passing null. In
some cases, PHP should be adjusted to make some function arguments
nullable. I have already fixed a number of functions before landing
this, but feel free to file a bug if you encounter a function that
doesn't accept null, but probably should. (The rule of thumb for
this to be applicable is that the function must have special behavior
for 0 or "", which is distinct from the natural behavior of the
parameter.)

RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

Closes GH-6475.
2021-02-11 21:46:13 +01:00

49 lines
1.2 KiB
PHP

--TEST--
openssl_x509_export() tests
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--
<?php
$cert_file = __DIR__ . "/cert.crt";
$a = file_get_contents($cert_file);
$b = "file://" . $cert_file;
$c = "invalid cert";
$d = openssl_x509_read($a);
$e = array();
var_dump(openssl_x509_export($a, $output)); // read cert as a binary string
var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string
var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails
var_dump(openssl_x509_export($d, $output4)); // read cert from a resource
try {
openssl_x509_export($e, $output5); // read an array, fails
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}
if (PHP_EOL !== "\n") {
$a = str_replace(PHP_EOL, "\n", $a);
}
var_dump(strcmp($output, $a));
var_dump(strcmp($output, $output2));
var_dump(strcmp($output, $output4));
var_dump($output3);
var_dump($output5);
?>
--EXPECTF--
bool(true)
bool(true)
Warning: openssl_x509_export(): X.509 Certificate cannot be retrieved in %s on line %d
bool(false)
bool(true)
openssl_x509_export(): Argument #1 ($certificate) must be of type OpenSSLCertificate|string, array given
int(0)
int(0)
int(%d)
NULL
NULL