SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 62
  1. #1
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    338
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Is PHP's OOP implementation complete?

    Quote Originally Posted by CS Geek View Post
    So, is PHP the best choice if I'm just starting? and is it good to develop big social websites in it?
    If you are just starting, PHP has insurmountable advantage over other programming languages for the webs, for reasons I already stated above. For a real big social website, the difference may not be that significant, and in fact PHP does lack certain OOP features to be called a complete OO language. In this case, you will have to decide for yourself.

  2. #2
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,524
    Mentioned
    52 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Hall of Famer View Post
    PHP does lack certain OOP features to be called a complete OO language.
    Like what, for example? Or compared to what?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    338
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Force Flow View Post
    Like what, for example? Or compared to what?
    Well, heres a list I can think of:

    1. Not everything is an object, string and array for instance.
    2. Impossible to achieve auto-boxing/auto-unboxing.
    3. No nested/anonymous class support.
    4. C# style property accessors syntax aint implemented.
    5. Not supporting wildcard namespace import like Java and C#.
    6. Metaprogramming not available, runkits may be a solution to this?

    Of course there are more, I may add them to the list later.

  4. #4
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,479
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    A programming language is Object Oriented if it satisfies 3 base principles:
    1. Encapsulation
    2. Polymorphism
    3. Inheritance

    Since PHP does satisfy all three, it doesn't matter what *some* think of *how much* object oriented it is or isn't!

    Quote Originally Posted by Hall of Famer View Post
    1. Not everything is an object, string and array for instance.
    In PHP every var is either an object, number, string or array. What else do you think they are? Also, not everything needs to be an object for it to be an object oriented language.

    Quote Originally Posted by Hall of Famer View Post
    3. No nested/anonymous class support.
    PHP has had anonymous classes for ages; they're more for using with properties than methods though.

    Quote Originally Posted by Hall of Famer View Post
    4. C# style property accessors syntax aint implemented.
    Is that a requirement somewhere that a language has to have C# style way of things to be qualified as an object oriented language? There were object oriented languages before there was C#.

    Quote Originally Posted by Hall of Famer View Post
    5. Not supporting wildcard namespace import like Java and C#.
    Namespaces are a bit new in PHP, they'll mature with time.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  5. #5
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    4 is proposed for PHP 5.6 as well

  6. #6
    SitePoint Enthusiast stelleninfotech's Avatar
    Join Date
    Apr 2013
    Location
    India
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP has many advantages over its competitors as web development through PHP is easier, fast and economic. That,s why it is widely preferred.

  7. #7
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    338
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Stormrider View Post
    4 is proposed for PHP 5.6 as well
    I wonder what else are proposed for PHP 5.6 though. I believe Metaprogramming is needed for PHP 5.6, the others can wait till PHP 6.0. The easiest way to get it done is to simply have runkit bundled with PHP like PDO and Memcached. It should not even be difficult, as all they have to do is to improve runkit's compatibility beyond PHP 5.3. I know runkit does not fully achieve metaprogramming, but it will help.

  8. #8
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Does PHP need that? Why is that so urgent?

  9. #9
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    664
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    /* ======================
     * 1 Read only attribute on member variables would save having to create numerous getters
     */
    class Buffy { public readonly $slainVampireCount: }

    /* ======================
     * 2 An immutable function which throws an exception on any write attempts
     * Basically a value object.  But be nice to have it apply to arrays as well.  Helps to make code more robust.
     */
    $buffy immutable(new Buffy('Buffy Summers'14304));
     */

    /* ======================
     * Type hinting and automatic getter/setter generator for member variables?
     * Already type hint for methods so why not for member variables
     *
     * Being able to specify standard getter/setters will drastically reduce boiler plate code as well as documentation annotations
     * Bonus points if type safe arrays can be handled as well
     */
    class Buffy 
        private 
    Address $address :  get;  // Functions as though getAddress() available
        
    private Person $fans: array, add// Collection with $fans->add(Person $person)  available

    /* ======================
     * Type hinting return values
     * Mostly for documentation but still handy
     */
    function Person getGreatestVampireSlayerEver() { return new Person('Buffy'); } 
    None of these are actually required or urgent but I think they would improve the quality of code and not be all that difficult to implement.

  10. #10
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    338
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Stormrider View Post
    Does PHP need that? Why is that so urgent?
    Yes PHP needs that, it makes plugin system so much easier to design.

  11. #11
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,825
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    I carefully agree with you too @Hall of Famer ;

    Personally, I think the lack of return types cripples PHP's OOP opportunities on a very high level. You can't adequately utilize Interfaces without a bit of concern. If I could tell my Interface, the type it should return for each method, that would give me the comfort knowing that a class that implements that interface will return an expected type. Today, that isn't the case, it could implement the parameters of the method, but return a completely different object.

    My work is big on the need for interfaces (they are a big part of API design), DI can use them for further extensible opportunities too, but without return types, it makes it difficult to fully trust them.

    Read-Only can "kind of" be implemented now, just create a private variable in your object and a public getter method, but having a readonly attribute would be a "nice to have".

    For auto boxing/unboxing, I can see the usefulness, but at the same time, I think readability is sometimes better knowing you have to ask to do it.

    Having everything be an object would be nice, though I'm not sure it is absolutely necessary. Granted the biggest limitation it has right now is you can't extend a string since it isn't an object (you'd actually have to recreate it).
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  12. #12
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,524
    Mentioned
    52 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ahundiak View Post
    PHP Code:
    /* ======================
     * 1 Read only attribute on member variables would save having to create numerous getters
     */
    class Buffy { public readonly $slainVampireCount: }

    /* ======================
     * 2 An immutable function which throws an exception on any write attempts
     * Basically a value object.  But be nice to have it apply to arrays as well.  Helps to make code more robust.
     */
    $buffy immutable(new Buffy('Buffy Summers'14304));
     */

    /* ======================
     * Type hinting and automatic getter/setter generator for member variables?
     * Already type hint for methods so why not for member variables
     *
     * Being able to specify standard getter/setters will drastically reduce boiler plate code as well as documentation annotations
     * Bonus points if type safe arrays can be handled as well
     */
    class Buffy 
        private 
    Address $address :  get;  // Functions as though getAddress() available
        
    private Person $fans: array, add// Collection with $fans->add(Person $person)  available

    /* ======================
     * Type hinting return values
     * Mostly for documentation but still handy
     */
    function Person getGreatestVampireSlayerEver() { return new Person('Buffy'); } 
    None of these are actually required or urgent but I think they would improve the quality of code and not be all that difficult to implement.
    If you want a read-only variable, use const.

    For getters/setters, you can use the magic methods __get() and __set(). Or, define your own functions. Or, make the variables public and access them through the object.

    PHP Code:
    class thing {
    public 
    $attribute=null;


    $newthing = new thing();
    $newthing->attribute='blue';
    echo 
    $newthing->attribute
    If you want documentation to appear, use PHPdoc syntax, which can be parsed in most IDEs that supports PHP.

    PHP Code:
    /**
    * function description here
    * @param string $input some comments here
    * @return string some comments here
    */
    function testme($input){
    return 
    $input;

    I think some of this boils down to partly unfamiliarity with PHP and partly wanting it to be something it is not.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  13. #13
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,479
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Force Flow View Post
    If you want a read-only variable, use const.
    You have to define a const with class definition and its value can't be changed. Read-only on the other hand can be set in a method (its rw within the class) but is read-only when accessed outside the class. That would definitely bring down the usage of getters.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  14. #14
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    338
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by asp_funda View Post
    You have to define a const with class definition and its value can't be changed. Read-only on the other hand can be set in a method (its rw within the class) but is read-only when accessed outside the class. That would definitely bring down the usage of getters.
    Good point. Also const does not accept arrays or objects, it only works for numbers, booleans and strings.

  15. #15
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,825
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    To help keep the other thread on topic, I've split the discussion around PHP's OOP to a new thread as I believe this to be a worthwhile discussion.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  16. #16
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem with doing everything by magic such as __get , __set and __call is that unless the @property/@method phpdoc is set they are a really ugly way to define public interfaces. Properties are a halfway house between the verbosity of getters/setters and the innocuous allure of seemingly easy to use __get __set approach( they are easy to use only when fresh in mind if they do not have doc annotation created by the original creator to show their intention ).

    Wanting it to be "something it is not" is one of those big issues, if you read php internals you will see it is very fractured with 3 quite distinct mind sets all with different view points of what it is and what it should be.
    1. Procedural bias - some even would like a PHP without classes.
    2. It should be forever newbie friendly and not be chosen for bigger projects( though when doing a projects outside of boutique work how can this be calculated? Don't pick the language unless it has a fixed termination and will delete itself at said time as a guarantee? ). This mentality gets a lot of things nos when voting. Also there seems to be a lot of bad experience of Java so anything even smelling of java gets a no. Java can be very productive, more productive than PHP with the right tooling and you have the other JVM languages like scala, groovy and kotlin etc which have some very interesting clean approaches.
    3. Those that look at how current competing languages are evolving and see if those methodologies can help keep php a competetive language in the larger scale of things. Even though this is split up into two groups, those who want a more dynamic less contractual language like ruby with monkey patching etc and those who want an optionally stricter language with clear self regulating call chains( typed return etc) when desired.

    If a language does not continually evolve to a standard greater than it is then programming in it is a dead end and that language is something to be outgrown of and left ASAP as a professional career path as it is a path to unfulfilling future employment, if employment can even be found in 15 years etc. Gotta play the long game keeping approaches and technologies current as there are a lot of unemployed IT people due to their physical age and non current experience.

    I remember very clearly when PHP as a language was a laughing stock on the quality front and you would not necessarily get a lot of respect as a developer for doing it. There are some very good key figures who have pushed this along literally fighting for good changes. Major language changes need 66% approval and that approval is very hard fought for, it definitely is not a glee club.

  17. #17
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    338
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Oops whats wrong with this thread? I dont recall starting this topic myself? o_o

    Edit: I see, but I merely said PHP's OOP is not complete as its missing some OO features, and thus cannot be called a complete object oriented language. For whatever they have implemented so far, I quite like them. XD

  18. #18
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,825
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hall of Famer View Post
    Edit: I see, but I merely said PHP's OOP is not complete as its missing some OO features, and thus cannot be called a complete object oriented language. For whatever they have implemented so far, I quite like them. XD
    Off Topic:

    Thread title updated to reflect that better

    I just didn't want to distract the other thread from its' original purpose with this discussion which has picked up pace over the past day. I also feel this discussion has been very good so far with a lot of discussions happening from both sides, so I wanted it to have the topic to itself.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  19. #19
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I agree with cpradio about the return values on interfaces. It's one of the biggest things about php that annoys me. That, and the fact that it's weakly typed, are two of my biggest personal gripes.

  20. #20
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    338
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    I see, it makes perfect sense, although after splitting the thread the other one seems to be dead. XD

    1. Procedural bias - some even would like a PHP without classes.
    I dont really quite get what you are saying, are there really people who prefer PHP without classes/objects? Thats complete nonsense if they seriously believe PHP is better off as a pure procedural language lol.

    And in terms of return value on interfaces, it can be a bit problematic for a dynamically typed language. I wonder if Python or Ruby has found ways to resolve this problem? Or is this a universal problem for all dynamically typed languages?

  21. #21
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On the return type thing I am in the very pro camp. There has been many rfcs on it alread ybut I believe Sarah Goldman and her facebook crew are doing some very cool things in the HHVM( virtual machine hip hop) world with generics, return types I think in AS3 format etc.. Trying to find documentation though is quite hard but personally if the facebook version gains solidity it may be the version to bet on. Fragmentation is bad but the needs of the community is already heavily fragmented.

  22. #22
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    664
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Force Flow View Post
    If you want a read-only variable, use const.
    And how do you go about having different const values for different instances? Answer: You don't. Think value objects?

    For getters/setters, you can use the magic methods __get() and __set(). Or, define your own functions. Or, make the variables public and access them through the object.

    PHP Code:
    class thing {
    public 
    $attribute=null;


    $newthing = new thing();
    $newthing->attribute='blue';
    echo 
    $newthing->attribute
    Don't want to. Just unnecessary clutter. Which is the point.

    If you want documentation to appear, use PHPdoc syntax, which can be parsed in most IDEs that supports PHP.

    PHP Code:
    /**
    * function description here
    * @param string $input some comments here
    * @return string some comments here
    */
    function testme($input){
    return 
    $input;

    Don't want to. Unnecessary clutter. I can almost always determine what the input values do by their names. Likewise, given the type I can usually determine the expected return value. No need to have extra annotations.

    I think some of this boils down to partly unfamiliarity with PHP
    At last something we can agree on!

    and partly wanting it to be something it is not.
    Which is sort of the point of having a wish list.
    Last edited by ahundiak; Aug 16, 2013 at 13:04. Reason: Made snarkness more subtle

  23. #23
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,479
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pbyrne84 View Post
    It should be forever newbie friendly and not be chosen for bigger projects
    I've actually heard/read that a lot over the years (that PHP isn't for big/enterprise projects, blah blah blah) & unsurprisingly almost 99% times the people who've ranted about it are the ones who don't know jack about what they were talking. I guess Facebook, Yahoo, Flickr, Wikipedia etc just don't know what they've been doing for years! I just ignore such (not so) well-informed & opinionated people now.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  24. #24
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,479
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ahundiak View Post
    Which is sort of the point of having a wish list.
    Wishing for a speedboat to be able to fly above clouds would be classified as a fantasy!
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  25. #25
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    57 Post(s)
    Tagged
    0 Thread(s)
    I love PHP. I really do, it pays my bills, mastering it gave me a new career. Still, I can't help but think its fate will eventually be the same as COBOL's, an archaic language with a lot of stuff written in it that no one wants to touch. PHP has a lot of design mistakes that can't be removed - if they could you'd have a much cleaner, easier to use and read language. As it stands though, the community is used to the warts and continues making code in spite of them.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •