Skip to content

Commit

Permalink
tests for isset(), unset()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkornaukhov03 committed Nov 1, 2024
1 parent c9790f9 commit a9fbe3c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/phpt/array_access/008_isset_unset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@ok
<?php
require_once 'kphp_tester_include.php';

function test_obj() {
$obj = new Classes\LoggingLikeArray(["zero", "one", "two", "str_key" => 42]);

var_dump(isset($obj[0]));
var_dump(isset($obj["str_key"]));
var_dump(isset($obj["non-existing-key"]));

unset($obj["str_key"]);
unset($obj[0]);

$keys = $obj->keys();
foreach ($keys as $key) {
var_dump($obj[$key]);
}

$obj[0] = "new";
var_dump(isset($obj[0]));
}

function test_mixed_in_obj() {
$obj = to_mixed(new Classes\LoggingLikeArray(["zero", "one", "two", "str_key" => 42]));

var_dump(isset($obj[0]));
var_dump(isset($obj["str_key"]));
var_dump(isset($obj["non-existing-key"]));

unset($obj["str_key"]);
unset($obj[0]);

if ($obj instanceof Classes\KeysableArrayAccess) {
$keys = $obj->keys();
foreach ($keys as $key) {
var_dump($obj[$key]);
}
}

$obj[0] = "new";
var_dump(isset($obj[0]));
}

test_obj();
test_mixed_in_obj();

0 comments on commit a9fbe3c

Please sign in to comment.