Yii3 Properties

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.

1 Like

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.

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.

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.

7 Likes

Yes, its true

@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.

2 Likes

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.
  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

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.

2 Likes

ā€˜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.

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

1 Like

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.

1 Like

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.

2 Likes

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.

1 Like

Oleg, Iā€™m afraid you do not own a motorbike :wink:

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

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.

1 Like

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

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.

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)?