Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Zend/tests/zpp/array_ht_or_long_zpp_specifier_strict_mode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--TEST--
Test array_ht_or_long ZPP specifier (strict_mode)
--EXTENSIONS--
zend_test
--FILE--
<?php

declare(strict_types=1);

$types = require 'types.inc';
$functions = [
'zend_array_ht_or_long',
'zend_array_ht_or_long_or_null',
];

foreach ($functions as $i => $function) {
echo "Using $function:\n\n";

foreach ($types as $name => $type) {
printf(" %-16s ", "$name:");

try {
$result = $function($type);

$result === []
? printf("array(0) {}\n")
: var_dump($result);

} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

if ($i !== array_key_last($functions)) {
echo "\n";
}
}

?>
--EXPECT--
Using zend_array_ht_or_long:

null: TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, null given
false: TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, false given
true: TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, true given
42: int(42)
73.5: TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, float given
'string': TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
'15': TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
'56.7': TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
'stdClass': TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
anon class name: TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
[]: array(0) {}
new stdClass(): TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, stdClass given
new S(): TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, S given
STDOUT: TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, resource given

Using zend_array_ht_or_long_or_null:

null: NULL
false: TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, false given
true: TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, true given
42: int(42)
73.5: TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, float given
'string': TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
'15': TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
'56.7': TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
'stdClass': TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
anon class name: TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
[]: array(0) {}
new stdClass(): TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, stdClass given
new S(): TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, S given
STDOUT: TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, resource given
81 changes: 81 additions & 0 deletions Zend/tests/zpp/array_ht_or_long_zpp_specifier_weak_mode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
--TEST--
Test array_ht_or_long ZPP specifier (weak_mode)
--EXTENSIONS--
zend_test
--FILE--
<?php

$types = require 'types.inc';
$functions = [
'zend_array_ht_or_long',
'zend_array_ht_or_long_or_null',
];

foreach ($functions as $i => $function) {
echo "Using $function:\n\n";

foreach ($types as $name => $type) {
printf(" %-16s ", "$name:");

try {
$result = $function($type);

$result === []
? printf("array(0) {}\n")
: var_dump($result);

} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

if ($i !== array_key_last($functions)) {
echo "\n";
}
}

?>
--EXPECTF--
Using zend_array_ht_or_long:

null:
Deprecated: zend_array_ht_or_long(): Passing null to parameter #1 ($param) of type array|int is deprecated in %s on line %d
int(0)
false: int(0)
true: int(1)
42: int(42)
73.5:
Deprecated: Implicit conversion from float 73.5 to int loses precision in %s on line %d
int(73)
'string': TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
'15': int(15)
'56.7':
Deprecated: Implicit conversion from float-string "56.7" to int loses precision in %s on line %d
int(56)
'stdClass': TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
anon class name: TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
[]: array(0) {}
new stdClass(): TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, stdClass given
new S(): TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, S given
STDOUT: TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, resource given

Using zend_array_ht_or_long_or_null:

null: NULL
false: int(0)
true: int(1)
42: int(42)
73.5:
Deprecated: Implicit conversion from float 73.5 to int loses precision in %s on line %d
int(73)
'string': TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
'15': int(15)
'56.7':
Deprecated: Implicit conversion from float-string "56.7" to int loses precision in %s on line %d
int(56)
'stdClass': TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
anon class name: TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
[]: array(0) {}
new stdClass(): TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, stdClass given
new S(): TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, S given
STDOUT: TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, resource given
73 changes: 73 additions & 0 deletions Zend/tests/zpp/array_ht_or_str_zpp_specifier_strict_mode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--TEST--
Test array_ht_or_str ZPP specifier (strict_mode)
--EXTENSIONS--
zend_test
--FILE--
<?php

declare(strict_types=1);

$types = require 'types.inc';
$functions = [
'zend_array_ht_or_str',
'zend_array_ht_or_str_or_null',
];

foreach ($functions as $i => $function) {
echo "Using $function:\n\n";

foreach ($types as $name => $type) {
printf(" %-16s ", "$name:");

try {
$result = $function($type);

$result === []
? printf("array(0) {}\n")
: var_dump($result);

} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

if ($i !== array_key_last($functions)) {
echo "\n";
}
}

?>
--EXPECTF--
Using zend_array_ht_or_str:

null: TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, null given
false: TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, false given
true: TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, true given
42: TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, int given
73.5: TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, float given
'string': string(6) "string"
'15': string(2) "15"
'56.7': string(4) "56.7"
'stdClass': string(8) "stdClass"
anon class name: string(%d) "class@anonymous%s"
[]: array(0) {}
new stdClass(): TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, stdClass given
new S(): TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, S given
STDOUT: TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, resource given

Using zend_array_ht_or_str_or_null:

null: NULL
false: TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, false given
true: TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, true given
42: TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, int given
73.5: TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, float given
'string': string(6) "string"
'15': string(2) "15"
'56.7': string(4) "56.7"
'stdClass': string(8) "stdClass"
anon class name: string(%d) "class@anonymous%s"
[]: array(0) {}
new stdClass(): TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, stdClass given
new S(): TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, S given
STDOUT: TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, resource given
73 changes: 73 additions & 0 deletions Zend/tests/zpp/array_ht_or_str_zpp_specifier_weak_mode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--TEST--
Test array_ht_or_str ZPP specifier (weak_mode)
--EXTENSIONS--
zend_test
--FILE--
<?php

$types = require 'types.inc';
$functions = [
'zend_array_ht_or_str',
'zend_array_ht_or_str_or_null',
];

foreach ($functions as $i => $function) {
echo "Using $function:\n\n";

foreach ($types as $name => $type) {
printf(" %-16s ", "$name:");

try {
$result = $function($type);

$result === []
? printf("array(0) {}\n")
: var_dump($result);

} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

if ($i !== array_key_last($functions)) {
echo "\n";
}
}

?>
--EXPECTF--
Using zend_array_ht_or_str:

null:
Deprecated: zend_array_ht_or_str(): Passing null to parameter #1 ($param) of type array|string is deprecated in %s on line %d
string(0) ""
false: string(0) ""
true: string(1) "1"
42: string(2) "42"
73.5: string(4) "73.5"
'string': string(6) "string"
'15': string(2) "15"
'56.7': string(4) "56.7"
'stdClass': string(8) "stdClass"
anon class name: string(%d) "class@anonymous%s"
[]: array(0) {}
new stdClass(): TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, stdClass given
new S(): string(7) "S class"
STDOUT: TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, resource given

Using zend_array_ht_or_str_or_null:

null: NULL
false: string(0) ""
true: string(1) "1"
42: string(2) "42"
73.5: string(4) "73.5"
'string': string(6) "string"
'15': string(2) "15"
'56.7': string(4) "56.7"
'stdClass': string(8) "stdClass"
anon class name: string(%d) "class@anonymous%s"
[]: array(0) {}
new stdClass(): TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, stdClass given
new S(): string(7) "S class"
STDOUT: TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, resource given
Loading
Loading