V
V
Vitaly2018-08-04 19:36:21
PHP
Vitaly, 2018-08-04 19:36:21

How to port a decorator function from python to php?

I am porting one application from python to php and there was a problem.
Faced with this kind of functions

@property
    def keys(self):
        return self.__keys

    @keys.setter
    def keys(self, mas):
        for k in mas:
            self.__keys.append(k.lower())

Here is the entire code of the file:
command_list = []


class Command:
    def __init__(self):
        self.__keys = []
        self.description = ''
        command_list.append(self)

    @property
    def keys(self):
        return self.__keys

    @keys.setter
    def keys(self, mas):
        for k in mas:
            self.__keys.append(k.lower())

    def process(self):
        pass

Googled something about anonymous functions, but I can't figure out how to apply
them. How to port them to php?
I've been suffering for 3 days now :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Dobryshin, 2018-08-04
@vitcorp

I don't understand what the problem is. In the first case, an array is returned from the object, in the second, strings are added to the end of the array.

function keys(self, mas=null) {
  if (func_num_args() == 1) {
             // один аргумент
  } else {
       // два аргумента
  }
}

Or do you definitely need a one-to-one code? Very often, the languages ​​do not match, and it becomes impossible to achieve a complete code match.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question