GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — short method references · Issue #2 · php-plus/engine

This repository was archived by the owner on Sep 17, 2019. It is now read-only.
This repository was archived by the owner on Sep 17, 2019. It is now read-only.

short method references #2

Copy link
Copy link
Open
Open
short method references#2
Copy link
Labels
rfcNew proposalNew proposal

Description

@olivernybroe
olivernybroe
opened on Sep 11, 2019
Issue body actions

So in PHP we can make a method reference by using this syntax right now

Route::get('users', [UserController::class, 'index']);

I propose that we add a short method reference syntax like so

Route::get('users', UserController::index);
Reacted by Julian Martin, Miguel Piedrafita, Jonathan Nessier, Oliver Nybroe, Marcin Harasim, Luis Canario and Fidel Aquino
Reacted by John Pedrie

Activity

  1. nunomaduro
    added
    rfcNew proposalNew proposal
    on Sep 11, 2019
  2. nunomaduro
    changed the title [-][RFC] Short method references[/-] [+]short method references[/+] on Sep 11, 2019
  3. stancl commented on Sep 11, 2019

    @stancl
    stancl
    on Sep 11, 2019
    More actions

    Should this work only with static access? It could be problematic with access inside the class because you can have a property and a method with the same name. $this->foo() and ($this->foo)() are different things.

    And with static methods, this is already possible. Strings that reference static methods are callable:

    >>> class Bar { public static function xyz() { return 'foo'; } }
    >>> 'Bar::xyz'();
    => "foo"
  4. olivernybroe commented on Sep 11, 2019

    @olivernybroe
    olivernybroe
    on Sep 11, 2019
    Author
    More actions

    @stancl This should work with non static method also. It should not be used for properties, only methods.
    As in my example, it would basically just be a wrapper for [Bar::class, 'xyz'], as that syntax also supports static methods.

    >>> class Bar { public static function xyz() { return 'foo'; } }
    >>> [Bar::class, 'xyz']();
    => "foo"
    

    The only "problem" I really see with it is that the same syntax is used for constants. However in that case, I think the constant should have priority.

  5. enumag commented on Sep 12, 2019

    @enumag
    enumag
    on Sep 12, 2019
    More actions

    The only "problem" I really see with it is that the same syntax is used for constants. However in that case, I think the constant should have priority.

    In real world constants are usually written in uppercase and methods in camelcase so it's not a real problem. In my opinion Plus should simply throw an error if a class has both a method and a constant with the same name.

    Reacted by Oliver Nybroe and Fidel Aquino
  6. olivernybroe commented on Sep 12, 2019

    @olivernybroe
    olivernybroe
    on Sep 12, 2019
    Author
    More actions

    @enumag Yeah, I like the idea of just throwing an error. And the uppercase/camelcase scenario was also why I sad "problem" 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    rfcNew proposalNew proposal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.