Partial Classes

  99791
July 6, 2017 08:11 khaweronline@gmail.com ("Khawer .")
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";
  }

}

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.
  99796
July 6, 2017 13:34 johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=)
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
  99799
July 6, 2017 15:09 michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=)
06.07.2017 15:34 "Johannes Schlüter" <johannes@schlueters.de> napisał(a):
> > 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?
Because class in few files won't autoload and more files cause you don't have class in one place and switching through files may increase frustration. Also this would lead to ambiguity if you load few partial classes which uses methods from not-loaded one how can you know where to find it?
> > > > 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 >