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

[php] return type declarations #11758

Open
PaulPatat opened this issue Sep 3, 2024 · 2 comments
Open

[php] return type declarations #11758

PaulPatat opened this issue Sep 3, 2024 · 2 comments
Labels
platform-php Everything related to PHP

Comments

@PaulPatat
Copy link

If I have this extern for a CakePHP class

package cake.orm;

import php.NativeArray;

@:native("Cake\\ORM\\Table")
extern class Table {
        function initialize(config:NativeArray):Void;
}

And this subclass

package app.model.table;

import cake.orm.Table;

class CookiesTable extends Table
{
        override function initialize(config):Void
        {
        }

}

Then this php is emitted

namespace app\model\table;
.....
       /**
         * @param array $config
         *
         * @return void
         */
        public function initialize ($config) {

But initialize() has a return type declaration from CakePHP 4 onward so this doesn't work too well:

class Table {
    public function initialize(array $config): void

It would be nice if extern methods could be annotated as having a return type so the compiler would emit overrides with the correct type.

@Simn Simn added the platform-php Everything related to PHP label Oct 16, 2024
@Simn
Copy link
Member

Simn commented Oct 16, 2024

So the problem is that the compiler doesn't emit the : void explicitly?

@PaulPatat
Copy link
Author

Yes. You'd subclass framework classes and override some methods so it has to obey the covariance and contravariance rules. Of course it's not just Void, for example you'd also override buildRules():

  public function buildRules(RulesChecker $rules): RulesChecker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-php Everything related to PHP
Projects
None yet
Development

No branches or pull requests

2 participants