Comments (7)
I am a user, I do not participate in the development, I think it is correct to check with isNullable, otherwise you have to parse the response to know if it is nullable or string
from php-generator.
For me is ok, if you set null with setNullable, you should check with:
echo $param->isNullable(); // true
from php-generator.
Why do I need to check isNullable
when I already know it by using setNullable
? I want to get the correct param type not the nullable
state.
from php-generator.
Why do you ask for the type if you already know that the answer is string? In large programs you won't know where the type is set or what type it is.
Example: I generate code with ->setType[$entity->getPhpType()].
from php-generator.
Why do you ask for the type if you already know that the answer is string?
It's just an example to reproduce the bug
In large programs you won't know where the type is set or what type it is.
Example: I generate code with ->setType[$entity->getPhpType()].
So what is your point then?. Your example is clearly the reason getType
should return the correct types
from php-generator.
isNullable
doesn't return true
in the case of ->setType('null|string')
but it does return true for ->setType('?string')
.
If you take a look at this Nette\Utils\Type::fromString
public static function fromString(string $type): self
{
// ...
if ($type[0] === '?') {
return new self([substr($type, 1), 'null']);
}
// ...
}
It is clear that the fromString
method is capable of parsing and returning the correct types. When using Nette\Utils\Type::fromString('?string')
, it correctly returns the expected types. However ->setType('?string')->getType()
doesn't (which uses Nette\Utils\Type::fromString
behind the scenes). With all the inconsistencies, I believe this is a bug.
Anyway, let the repository owner decide on further actions regarding this report.
from php-generator.
This behavior is for historical reasons, because functions were created at a time when union types like null|string
didn't even exist yet. I would like to change this, but it will break compatibility.
from php-generator.
Related Issues (20)
- class names resolving in use as
- Inline comment of constant lost HOT 1
- Automatically build nested attributes from object HOT 2
- Methods with one parameter are printed as multiline if promoted or with attribute HOT 1
- ClassType->getNamespace() should not be deprecated HOT 5
- Using comment before for parameter throws exception HOT 2
- Leading slash in alias use at class line HOT 2
- Nullable union type HOT 1
- Attributes cant have 0 as parameter HOT 1
- Extract fails on array properties with class constant keys
- Breaking change within minor version bump RE: namespaces HOT 7
- Printing empty namespace HOT 5
- Option to force keys on arrays in properties HOT 3
- PhpParser\Lexer\Emulative::__construct(): Argument #1 ($phpVersion) must be of type ?PhpParser\PhpVersion, array given HOT 2
- Heredoc and Nowdoc converted to inline string when parsed HOT 4
- Option to set or overwrite a method. HOT 2
- Support for PER Coding Style 2.0 HOT 2
- Promoted Parameters don't have "readonly" when using Factory HOT 1
- Add support for "Roave/BetterReflection" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-generator.