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
71 changes: 71 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,71 @@
--TEST--
Test array_ht_or_long ZPP specifier (strict_mode)
--EXTENSIONS--
zend_test
--FILE--
<?php

declare(strict_types=1);

$types = require 'types.inc';

foreach ($types as $name => $type) {
echo "Using $name:\n";
try {
var_dump(zend_array_ht_or_long($type));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
var_dump(zend_array_ht_or_long_or_null($type));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

?>
--EXPECT--
Using null:
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, null given
NULL
Using false:
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, false given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, false given
Using true:
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, true given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, true given
Using 42:
int(42)
int(42)
Using 73.5:
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, float given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, float given
Using 'string':
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
Using '15':
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
Using '56.7':
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
Using 'stdClass':
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
Using anon class name:
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
Using []:
array(0) {
}
array(0) {
}
Using new stdClass():
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, stdClass given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, stdClass given
Using new S():
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, S given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, S given
Using STDOUT:
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, resource given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, resource given
79 changes: 79 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,79 @@
--TEST--
Test array_ht_or_long ZPP specifier (weak_mode)
--EXTENSIONS--
zend_test
--FILE--
<?php

$types = require 'types.inc';

foreach ($types as $name => $type) {
echo "Using $name:\n";
try {
var_dump(zend_array_ht_or_long($type));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
var_dump(zend_array_ht_or_long_or_null($type));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

?>
--EXPECTF--
Using 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)
NULL
Using false:
int(0)
int(0)
Using true:
int(1)
int(1)
Using 42:
int(42)
int(42)
Using 73.5:

Deprecated: Implicit conversion from float 73.5 to int loses precision in %s on line %d
int(73)

Deprecated: Implicit conversion from float 73.5 to int loses precision in %s on line %d
int(73)
Using 'string':
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
Using '15':
int(15)
int(15)
Using '56.7':

Deprecated: Implicit conversion from float-string "56.7" to int loses precision in %s on line %d
int(56)

Deprecated: Implicit conversion from float-string "56.7" to int loses precision in %s on line %d
int(56)
Using 'stdClass':
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
Using anon class name:
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, string given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, string given
Using []:
array(0) {
}
array(0) {
}
Using new stdClass():
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, stdClass given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, stdClass given
Using new S():
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, S given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, S given
Using STDOUT:
TypeError: zend_array_ht_or_long(): Argument #1 ($param) must be of type array|int, resource given
TypeError: zend_array_ht_or_long_or_null(): Argument #1 ($param) must be of type array|int|null, resource given
71 changes: 71 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,71 @@
--TEST--
Test array_ht_or_str ZPP specifier (strict_mode)
--EXTENSIONS--
zend_test
--FILE--
<?php

declare(strict_types=1);

$types = require 'types.inc';

foreach ($types as $name => $type) {
echo "Using $name:\n";
try {
var_dump(zend_array_ht_or_str($type));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
var_dump(zend_array_ht_or_str_or_null($type));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

?>
--EXPECTF--
Using null:
TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, null given
NULL
Using false:
TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, false given
TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, false given
Using true:
TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, true given
TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, true given
Using 42:
TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, int given
TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, int given
Using 73.5:
TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, float given
TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, float given
Using 'string':
string(6) "string"
string(6) "string"
Using '15':
string(2) "15"
string(2) "15"
Using '56.7':
string(4) "56.7"
string(4) "56.7"
Using 'stdClass':
string(8) "stdClass"
string(8) "stdClass"
Using anon class name:
string(%d) "class@anonymous%s"
string(%d) "class@anonymous%s"
Using []:
array(0) {
}
array(0) {
}
Using new stdClass():
TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, stdClass given
TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, stdClass given
Using new S():
TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, S given
TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, S given
Using STDOUT:
TypeError: zend_array_ht_or_str(): Argument #1 ($param) must be of type array|string, resource given
TypeError: zend_array_ht_or_str_or_null(): Argument #1 ($param) must be of type array|string|null, resource given
71 changes: 71 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,71 @@
--TEST--
Test array_ht_or_str ZPP specifier (weak_mode)
--EXTENSIONS--
zend_test
--FILE--
<?php

$types = require 'types.inc';

foreach ($types as $name => $type) {
echo "Using $name:\n";
try {
var_dump(zend_array_ht_or_str($type));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
var_dump(zend_array_ht_or_str_or_null($type));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

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