zephir-lang / zephir

Zephir is a compiled high-level language aimed to ease the creation of C-extensions for PHP
https://zephir-lang.com
MIT License
3.31k stars 466 forks source link

Remove "Old Style" constructor support from Zephir #1803

Closed dschissler closed 3 years ago

dschissler commented 5 years ago

Since Zephir is going PHP 7.2+ then this feature can be removed from latest Zephir. Simply delete out the Zephir compiler code that treats it as a constructor.

Constructors and Destructors.

Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code.

Also


<?php
namespace Foo;
class Bar {
    public function Bar() {
        // treated as constructor in PHP 5.3.0-5.3.2
        // treated as regular method as of PHP 5.3.3
    }
}
?>

I'd like to be able to compile the following Zephir but I can't.

namespace Perch\Translate;

class Gettext
{

    public function gettext(message) -> string
    {
        return gettext(message);
    }
}

Refs: https://github.com/phalcon/zephir/issues/934

dschissler commented 5 years ago

Another weird point:

As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn't affect non-namespaced classes.

So all Zephir could have this removed since Zephir classes will always be namespaced. So this has basically never been relevant in the lifetime of Zephir, which is PHP 5.3.3+.

Now I have to rename either my Gettext class and namespace or the gettext method. Really annoying! I've had to bleed all over the damn place to get my extension to the place it is now.

dschissler commented 5 years ago

Correction, I can compile it but it crashes PHP and so I have to delete my installed extension to be able to continue. So somehow PHP is treating classes from the Zephir compiled .so as different than normal PHP. At any rate with whatever solution this is bad behaviour.