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

[zend-validate] Ensure value is a string prior to validation #100

Closed
wants to merge 1 commit into from

Conversation

glensc
Copy link
Contributor

@glensc glensc commented Sep 10, 2021

Method expects a string value. If a float is
passed in PHP 7.4 will issue a notice for
trying to access array offset.

Carry Shardj/zf1-future#151

cc @davejennings

Method expects a string value. If a float is
passed in PHP 7.4 will issue a notice for
trying to access array offset.

Signed-off-by: Elan Ruusamäe <[email protected]>
@glensc glensc mentioned this pull request Sep 10, 2021
@glensc glensc changed the title Ensure value is a string prior to validation [zend-validate] Ensure value is a string prior to validation Sep 10, 2021
Copy link
Member

@falkenhawk falkenhawk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we have a test for this case please 😅

@falkenhawk
Copy link
Member

I wonder what kind of notice did the original code issue?

public static function isInteger($value, array $options = array())

the first argument is not required to be string, it's only type-hinted in phpdoc.

Then inside Zend_Locale_Format::isNumber() the value is casted to string anyways.

I also saw there are cases for non-string floats + locale in

public function testBasic()
but I could not spot any relevant notice to be thrown in a PHP 7.4 test run on master https://github.com/zf1s/zf1/runs/3565219911 🤔

@davejennings
Copy link

For reference, issue I had was along the lines of this test:

<?php

class Zend_Validate_IntTest extends \PHPUnit\Framework\TestCase
{

    public function testNoticeOnFloatValidation()
    {
        $this->obj = new Zend_Validate_Int();
        $this->assertFalse($this->obj->isValid(0.1));
    }
}

Which resulted in:

1) Zend_Validate_IntTest::testNoticeOnFloatValidation
Trying to access array offset on value of type float

/vendor/shardj/zf1-future/library/Zend/Locale/Format.php:527
/vendor/shardj/zf1-future/library/Zend/Locale/Format.php:727
/vendor/shardj/zf1-future/library/Zend/Validate/Int.php:139
/tests/library/ZF1/Validate/Zend_Validate_IntTest.php:9

Quoting the float as a string worked but that's not how I interpreted the intention of the original ZF code. Going back a bit and I've had a baby since then though, so my memory isn't to be trusted.

@falkenhawk
Copy link
Member

falkenhawk commented Sep 10, 2021

@davejennings thank you very much for taking your time to provide more details here!

It appears we have already tackled the issue in #16 ( https://github.com/zf1s/zf1/pull/16/files#diff-1782ecc91bb385acd1ea87235135268a0f47f2670f7fe63fe02b08017ef33801R510 )
by taking a more general approach and casting the $input var to string in Zend_Locale_Format::isNumber(), so I am going to close this PR.

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

Successfully merging this pull request may close these issues.

3 participants