Skip to content

Function chained call - #301

Closed
laruence wants to merge 6 commits into
php:masterfrom
laruence:function_chained_call
Closed

laruence wants to merge 6 commits into
php:masterfrom
laruence:function_chained_call

Conversation

@laruence

@laruence laruence commented Mar 8, 2013

Copy link
Copy Markdown
Member

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

laruence commented Mar 9, 2013

Copy link
Copy Markdown
Member Author

the invalid free one has been fixed in 98a36c8

@Majkl578

Majkl578 commented Mar 9, 2013

Copy link
Copy Markdown
Contributor

👍

Also consider this syntax:

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

@laruence

laruence commented Mar 9, 2013

Copy link
Copy Markdown
Member Author

invalid reads and invliad free must be fixed..

@weltling

Copy link
Copy Markdown
Contributor

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

@laruence

Copy link
Copy Markdown
Member Author

@weltling thanks :)

@nubs

nubs commented Jun 3, 2013

Copy link
Copy Markdown

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

nikic commented Jun 3, 2013

Copy link
Copy Markdown
Member

@nubs Yes.

@nubs

nubs commented Jun 4, 2013

Copy link
Copy Markdown

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

@felipensp

Copy link
Copy Markdown
Contributor

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

@laruence

Copy link
Copy Markdown
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

Majkl578 commented Jun 1, 2014

Copy link
Copy Markdown
Contributor

What happened to this amazing feature?

@laruence

laruence commented Jun 1, 2014

Copy link
Copy Markdown
Member Author

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

@laruence laruence reopened this Jun 1, 2014
@laruence

Copy link
Copy Markdown
Member Author

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

@laruence laruence closed this Aug 19, 2014
@mbrevda

mbrevda commented Dec 23, 2014

Copy link
Copy Markdown

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