C#-like extension methods in PHP? -


The way you can type an extension method in C #, and then work like this:

  string ourString = "hello"; OurString.MyExtension ("Another");  

or even

  "hello" .missation ("other");  

Is there such behavior in PHP?

If you can re-implement all your strings as objects.

  class MyString {... function foo () {...}} $ str = new MyString ('bar'); $ Str- & gt; Foo ('baz');  

But you really would not like to do this. PHP is not just an object-oriented language in its original, strings are just primitive types and there is no way.

'Bar' - & gt; Foo ('baz') It is impossible to get in PHP without extending the CXX core engine (which you do not want to minimize for this purpose :)).


There is nothing about expansion in it's functionality of an object which basically improves by writing a new function which accepts a primitive. In other words, PHP's equivalent

  "Hello". My extension ("Other");  

is

  my_extension ("hello", "other");  

This is the same functionality for all intents and purposes, just different syntax.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -