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

Function chained call #301

Closed
wants to merge 6 commits into from
Closed

Conversation

laruence
Copy link
Member

@laruence laruence commented Mar 8, 2013

This will allow such syntax:

<?php
(function(){})(); // call an closure
?>
<?php
(func())(); // function chained calls
?>
<?php
class D {
   public function __invoke() {}
}

(new D)(); // call invoke
?>

this patch is refactored, in order to based on the @nikic 's instance call one(#291). maybe we can merge them together..

btw: there are some invalid reads report while run with valgrind,, but it seems introduces by nikic's patch,

I will keep looking them.

@laruence
Copy link
Member Author

laruence commented Mar 9, 2013

the invalid free one has been fixed in 98a36c8

@Majkl578
Copy link
Contributor

Majkl578 commented Mar 9, 2013

👍

Also consider this syntax:

[..., ...]() // invokes a callback

@laruence
Copy link
Member Author

laruence commented Mar 9, 2013

invalid reads and invliad free must be fixed..

@weltling
Copy link
Contributor

On windows all tests pass for me, mazeltov! :)

@laruence
Copy link
Member Author

@weltling thanks :)

@nubs
Copy link

nubs commented Jun 3, 2013

Will this allow for immediately calling closures from require/include calls as well? Something like this:

<?php
// getItem.php
return function(MongoDB $db) {
    return function($name) use($db) {
        return $db->findOne(['name' => $name]);
    };
};
?>

<?php
// test.php
$db = (new Mongo())->myDatabase;
$getItem = (require 'getItem.php')($db); // This is the the line relevant to the question

$item = $getItem('test');
?>

@nikic
Copy link
Member

nikic commented Jun 3, 2013

@nubs Yes.

@nubs
Copy link

nubs commented Jun 4, 2013

Awesome, I wasn't sure if this would apply to a language construct or not, glad to hear that it would.

@felipensp
Copy link
Contributor

Good job guys, have you already written a RFC and proposed it?

@laruence
Copy link
Member Author

Nope, since this PR is based on @nikic 's , I assume he will write a RFC. then I will merge this PR into his proposal :)

@laruence laruence closed this Jun 1, 2014
@laruence laruence deleted the function_chained_call branch June 1, 2014 03:41
@Majkl578
Copy link
Contributor

Majkl578 commented Jun 1, 2014

What happened to this amazing feature?

@laruence
Copy link
Member Author

laruence commented Jun 1, 2014

hmmm, I closed it by accident..... .:<

@laruence laruence reopened this Jun 1, 2014
@laruence
Copy link
Member Author

close this as it will be implemented in uniform variable style by @nikic

@laruence laruence closed this Aug 19, 2014
@mbrevda
Copy link

mbrevda commented Dec 23, 2014

For reference, I think @laruence was refering to #686, which was merged to phpng

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.

7 participants