dan-da / py2php

py2php is a utility that will auto-translate python code into PHP code.
GNU General Public License v2.0
98 stars 32 forks source link

new object creation #7

Closed gareth-ib closed 6 years ago

gareth-ib commented 6 years ago
        bin_factory = BinFactory(width, height, count, self._pack_algo, **kwargs)

converts to

$bin_factory = py2php_kwargs_function_call('new BinFactory', [$width,$height,$count,$this->_pack_algo], $kwargs);

but should be more like...

$bin_factory = new BinFactory( $width,$height,$count,$this->_pack_algo, $kwargs );

although there is a separate issue related to that **kwargs param. I'm not 100% sure what python expects that to be. I'll make it a separate ticket :)

dan-da commented 6 years ago

There's a fix for this in 327fca32a2e1554e311ef1b1e3e47b337463d8bf. Well, the generated code remains the same but py2php_kwargs_function_call() is now able to detect the call to new and assemble the constructor's arguments accordingly from the named params. So the generated code executes correctly.

I added an example of this in tests/namedparameters.py

gareth-ib commented 6 years ago

nice thanks. I've been fixing these things by hand now so I won't be re-running the script anymore cuz it would overwrite my manual changes. Just letting you know what I come across :)

I do think in most cases it'd be better to replace the code with the call as opposed to calling your method to figure it out on the fly