Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different results using local and composer loaded Inspekt #8

Open
williamsdb opened this issue Sep 24, 2015 · 1 comment
Open

Different results using local and composer loaded Inspekt #8

williamsdb opened this issue Sep 24, 2015 · 1 comment

Comments

@williamsdb
Copy link

When caging my own array and then checking an element of that array I get different result depending on whether I am using the version of Inspekt downloaded from github as opposed to the version from composer.

For example this works without errors:

<?php
    require_once('inc/Inspekt.php');

    $test = array();
    $test['params'][] = "hello";

    // cage the array
    $params_cage = Inspekt_Cage::Factory($test);
    $one = $params_cage->getAlnum('params/0');
    $two = $params_cage->getInt('params/1');
 ?>

However, if I run the following:

<?php
    require __DIR__ . '/vendor/autoload.php';

    // Inspekt initialisation
    use Inspekt\Inspekt;
    use Inspekt\Cage;

    $test = array();
    $test['params'][] = "hello";

    // cage the array
    $params_cage = Cage::Factory($test);
    $one = $params_cage->getAlnum('params/0');
    $two = $params_cage->getInt('params/1');
?>

Gives the following error:

Fatal error: Uncaught exception 'Inspekt\Exception' with message 'Key '1' does not exist' in /home/ubuntu/workspace/vendor/funkatron/inspekt/src/Inspekt/Cage.php:992 
Stack trace: #0 /home/ubuntu/workspace/vendor/funkatron/inspekt/src/Inspekt/Cage.php(985): Inspekt\Cage->getValueRecursive(Array, Object(ArrayObject), 1) 
#1 /home/ubuntu/workspace/vendor/funkatron/inspekt/src/Inspekt/Cage.php(954): Inspekt\Cage->getValueRecursive(Array, Object(ArrayObject)) 
#2 /home/ubuntu/workspace/vendor/funkatron/inspekt/src/Inspekt/Cage.php(394): Inspekt\Cage->getValue('params/1') 
#3 /home/ubuntu/workspace/it.php(15): Inspekt\Cage->getInt('params/1') 
#4 {main} thrown in /home/ubuntu/workspace/vendor/funkatron/inspekt/src/Inspekt/Cage.php on line 992

Given that you cannot check for null on a caged array (I don't think) this latter functionality makes caging of your arrays less useful.

@funkatron
Copy link
Collaborator

Yeah, that is a change in the newest versions (0.6.x). I made a change yesterday in the testXXX() methods, where they will return false if the key does not exist. The change is only in the master branch right now. See 6f91ee0 and f953fb9. With these changes, if you use $params_cage->testInt(), I you will get the behavior you expect.

Let me know if that works for you. If so I'll tag a 0.6.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants