xsd2php icon indicating copy to clipboard operation
xsd2php copied to clipboard

PHP7 Typehinting support

Open captn3m0 opened this issue 9 years ago • 4 comments

For something like:

<?php
/**
     * Sets a new verifiedName
     *
     * @param string $verifiedName
     * @return self
     */
    public function setVerifiedName($verifiedName)
    {
        $this->verifiedName = $verifiedName;
        return $this;
    }

Makes sense to use php7 scalar typehints here. Could be hidden behind a flag in config.yml. I'll try to work on a PR if this sounds helpful?

captn3m0 avatar Nov 16 '16 07:11 captn3m0

Hi, tanks for the suggestion. The feature proposal looks nice. Currently there are some issues with it:

  • i'm not sure that the 2.x version of the zend code generator supports scalar type hinting -- (of course i will be happy to upgrade it)
  • im not sure how php will behave with objects having the "toString" method. in many places, objects are use as value objects to represent strings
  • of course this should be a configurable option for those that do not have php 7

What are your opinions?

goetas avatar Nov 16 '16 09:11 goetas

  1. Just noticed that zend-code now supports php7 scalar typehinting in v3: https://github.com/zendframework/zend-code/pull/30
  2. Scalar typehinting would break with toString() I think. I'll check and update again.
  3. Agree on it being configurable as an option.

captn3m0 avatar Dec 23 '16 09:12 captn3m0

I agree for all your points.

toString can be easily fixed doing some string casting inside.

I'm only worried for the works that needs to be done to port the code to use zend-code v3...

goetas avatar Dec 23 '16 10:12 goetas

In the last few days, I've had to modify this project to use zend-code 3.3 and generate classes with PHP7.1 parameter and return types for a project I'm working on.

The amount of work to update this project to use zend-code v3 is quite little (see commit).

I've sadly not yet had time to convert my changes into bite-sized pull requests. You might want to have a look at the commits to see whether any of the changes are interesting for this project, so I can perhaps extract them to PRs later on.

allcode avatar Nov 14 '17 19:11 allcode