Yii3 Properties

(Oleg) #1

Currently, PHP does not have property support as it works in for example C#.

Yii1/2 has an elegant solution where this functionality implemented using __set and __get.
In Yii3 developers try to abandon this convenient feature, and there is a reasons for that.

  1. We are unable to have completely own hierarchy, we need to inherit from Yii classes.
  2. We can not use our code outside Yii framework
  3. We can not see if property is read-only or write-only

My solution problems:

  1. To implement property functionality as trait.
  2. Move trait to very compact library, for example yii/foundation.
  3. This could be solved with PHPStorm plugin

So internal framework classes would use trait.
User will be able to choose to use just public class fields or use yii/foundation dependancy.

(Alexander Makarov) #2

There is no need for internal classes to use properties.

The feature could be implemented with trait so anyone could use it but I haven’t seen any demand for it yet.

(Oleg) #3

I personally hate $x->setY($value) and $y->getY(). I hate every second I do this in Symfony.
It makes classes much bigger and less readable, it makes code more bloated.

And in 7.4 explicit getters/setters could become obsolete.

And In my opinion, people in the topic Naming: getters, setters, methods agree with me

Btw I ment not internal, but framework classes used by framework user.

(Alexander Makarov) #4

https://wiki.php.net/rfc/typed_properties_v2 won’t solve the problem of value validation. It can only validate type. Also it won’t allow caching properties, lazy access or anything like that. So no, 7.4 won’t make methods obsolete.

Yes, I understood that. The thing is that I don’t want Yii to continue being closed community. I don’t want the situation that using a third party library is inconvenient without a wrapper extension. I don’t want thousands of these wrapper extensions doing just wrapping. Yii 3 is meant to work with any PHP classes without wrappers and to reuse PSR-compatible libraries.

(Oleg) #5

Yes, its true

(Oleg) #6

@samdark Actually in my opinion nothing in the replay is true. But I am not sure if there is a place for discussion about specific things, because I see there more deep problem: absense of global vision how to move framework to new level, Yii3 features is just following histeric comments in the internet. I think the true is that every argument there has its trade-offs: Openess like in Symfony - overcomplication, sugar and SOLID principles in Laravel - low execution speed. I personally would like to see Yii more like Django (All batteries included > rapid development) but with 100% code completion (near 100% refactoring possibilities) and static code check (lint) before execution like in ASP.NET. And of couse I believe worst thing will be to break backward compatability.

(Alexander Makarov) #7

It’s fine to discuss specific things.

What is the reason for this conclusion?

Well, no. There are some things that address parts that are often in “histeric comments” but not because these comments are loud but because these parts are important.

That’s great mix of wishes but…

  1. You can’t get anything fundamentally improved in Yii 2 without breaking things. Features could be added, enhancements could be made but no PSRs, no support for async runners that boost performance to the skies, no easy unit testing, etc. etc.
  2. 100% code completion can’t be achieved if there’s any sort of magic. Same for 100% refactoring possibilities. That’s one of the pros of Yii 3. There’s almost no magic.
  3. Static code check (lint) before execution isn’t generally possible in PHP. There are type hints used everywhere in Yii 3 so runtime checks are there. If anything goes wrong, you know it early.

(Oleg) #8
  1. I ment mostly extensions, not users’ projects. It is not easy, but probably possible to have some extension yii3/backcompatability, that emulates yii2 on yii3 framework.
  2. It could be achived with PhpStorm plugin.
  3. To achive this yii3 need to have 2. Than PHPStorm probably could have a button to read all files in project.

I suppose PHP have beautifull ecosystem with meriads of packages and most of them have good license. Did you consider to use and “steal” (fork) code from other projects?
For example: Active Record/Data Mapper - Propel3, Core classes (Router, Console, Process, Forms) - Symfony, Collections - Laravel, Admin panel - laravel, Strings - danielstjules/stringy and so on. Just assemle best packages, those have complicated APIs or not compatable - fork, and make own versions.

So basicly to create MetaFramework

(Alexander Makarov) #9

Yes, it is possible to some degree. We’ll get back to it when most features will be completed.

Could be done with the plugin but it’s not the end of the story. If it’s standard PHP all the static analysis tools could be fully used. CI, PhpStan, Psalm… everything. We can not develop custom plugins for all these.

That is usually done by static analysis and continuous integration. See point above.

We already use some high quality packages but as dependencies, not as forks.

Propel is pretty much dead as far as I know. We’re going to make Yii being able to work with any database layer. Developing our own is a big question and likely it won’t be in the first release.

We’re relying on FastRoute. Console is Symfony. Forms will likely be our own.

I don’t see any point in that package.

Do you mean reselling Nova for $199?

We have our own.

Yii 3 is a meta-framework to some degree already. The difference from something like Slim is that we still have our own high quality packages.

(Breg) #10

‘Absence of global vision’ is exactly what I expect from a tool.
I don’t want a global vision in my 3D printer, CNC mill, in my motorbike or my heating system.
So I also don’t want it in a web framework, and I don’t see the possible benefit as well.

(Oleg) #11

My mistake, after looking in Yii3 sources I found both global vision and perspective :slight_smile:

(Oleg) #12

Web framework is not a hammer, it is a the way of doing things. At least in high concurent market as market of php web frameworks. Look at laravel, “Framework for artisans”. Look at symfony, "a set of reusable PHP “components”. They have clear vision, clear identity, they dictate a way how to develop. To choose web framework is like to choose cloth - it reflects how you feel yourself, and how you prefer doing things. Laravel - lot of sugar and “shiness”, Symfony - “correct” “enterprise” way, Yii2 - practical way.

(Oleg) #14

Unfortunatly in Yii’s practical way there is a missing part, after project grows it becames less and less maintainable and Yii3 moving to right direction regarding this.

(Alexander Makarov) #15

I still think that we can get the best from both practical way and correct way. Will see closer to release if that’s true.

(Breg) #16

Oleg, I’m afraid you do not own a motorbike :wink:

(Oleg) #17

Not sure what you mean, probably that motorbike is a lifestyle like web framework (at least for geek).

(Breg) #18

In the beginning it may look like a lifestyle decision, but over the years, as problems arise, and you have to disassemble components, or you want to change something, the technical details become more important.
And then simplicity is the main virtue, and elegant-simple construction.
With a hammer there is no alternative how to construct it, it’s always simple.

(Oleg) #19

Simple things on the outside often are quite complex inside, and opposite is also true. For example CodeIgniter is much more simple than Yii, buy it is more diffecult to use, for example it is not IDE friendly.

I disagree that simplicity is the main virtue, I think you mix simplicity and well build. Well thought out things usually works as simple possible because complexity adds upp very quickly, and not optimal solutions just would collapse under its weight.

Everything should be made as simple as possible, but no simpler

Original: It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience. Albert Einstein

(Oleg) #20

And I did not say that technical things are not important, it all about technology, I said that every product must have some global concepts, ideology. It helps to synchronize “moving” parts and make work product as one “organism”, not just a set of tools.

(Breg) #21

Einstein speaks about scientific theories, not (technical) constructions.
For these one has to add the phrase ‘for a given task’.
And in a web framework the builders / programmers choose the task.
Now here we discuss what the task is, or should be. You request the kind of simplicity and abstraction that Laravel (seems to) offer, and I prefer more inner simplicity, which I see at Yii.

And no, not every product must have global concepts, there are much more examples that proove this theory wrong than right. What is the global concept in a CNC mill (just to avoid the much simpler and thus maybe misleading hammer example)?