Skip to content

Conversation

@webNeat
Copy link
Contributor

@webNeat webNeat commented Jun 27, 2016

Hello, I added this test case

public function test_curry_using_func_get_args()
{
    $fnNoArgs = C\curry(function () { return func_get_args(); });
    $this->assertEquals([], $fnNoArgs());
    $this->assertEquals([1], $fnNoArgs(1));
    $this->assertEquals([1, 2, 'three'], $fnNoArgs(1, 2, 'three'));

    $fnOneArg = C\curry(function ($x) { return func_get_args(); });
    $this->assertEquals([1], $fnNoArgs(1));
    $this->assertEquals([1, 2, 'three'], $fnNoArgs(1, 2, 'three'));

    $fnTwoArgs = C\curry(function ($x, $y) { return func_get_args(); });
    $curried = $fnTwoArgs(1);
    $this->assertEquals([1, 2], $fnNoArgs(1, 2));
    $this->assertEquals([1, 2, 'three'], $fnNoArgs(1, 2, 'three'));
    $this->assertEquals([1, 2], $curried(2));
    $this->assertEquals([1, 2, 'three'], $curried(2, 'three'));
}

And fixed the code to make it pass.

@matteosister
Copy link
Owner

any idea on why the test is failing??

Beside the fact that I simply should deprecate php 5.3 and 5.4 😄

@webNeat
Copy link
Contributor Author

webNeat commented Jun 27, 2016

Well now we have

function curry($callable)
{
    if (_number_of_required_params($callable) < 2)
        return $callable;
    return _curry_array_args($callable, _rest(func_get_args()));
}

So in case of $callable = array(new TestSubject(), 'identity') it's simply returned because it has only 1 parameter. And in this case, we end up having $identity = array(new TestSubject(), 'identity'). So doing $identity(1) gives FATAL ERROR Function name must be a string on PHP 5.3

Here is a sample code demonstrating the issue:

<?php
class TestSubject
{
    public function identity($a) {
        return $a;
    }
}

$add = array(new TestSubject(), 'identity');

echo $add(1);

This code works for PHP 5.4+ but not for PHP 5.3 !

@matteosister matteosister merged commit 7da7183 into matteosister:master Jun 27, 2016
@matteosister
Copy link
Owner

👍 merged! many thanks!

@matteosister
Copy link
Owner

a new release is coming...

@webNeat
Copy link
Contributor Author

webNeat commented Jun 28, 2016

Thank you for merging that 😄

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.

2 participants