On Do, 2017-07-06 at 13:11 +0500, Khawer . wrote:
> Partial Classes
> 
> If we are using same class for different purposes we can extend it,
> and add new properties and methods. But we will also have to use new
> class name, when we create objects. C# provides a better concept
> "Partial Classes". Why not to also implement it in PHP?
> 
> Example:
> 
> Partial Class abc {
> 
>   public function sayhi() {
>    echo "Hi";
>   }
> 
> }
> 
> Partial Class abc {
> 
>   public function sayhello() {
>    echo "Hello";
>   }
> 
> }

My understanding is that C# mostly uses this for GUI stuff where
forms/widgets are designed in a visual editor and code is written in
text. By using partial classes those can be in different files, thus
developers don't touch generated files.

Except for that a need for splitting this up indicates a design issue
to me. Like a class doing too many things.

PHP has traits which you eventually can use to emulate such a system in
a more explicit way.
http://php.net/traits

> Q: What will happen if both classes contain same method names?
> A: We will show error method already exists.
> 
> Q: Will it break any existing code?
> A: No, there will be no impact on any existing coding because we are
> not changing anything.

It would break usage of "partial" which is not a keywor, yet.

johannes


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to