Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question it doesnt recognize OOP??

    PHP Code:
    <?php
    class Cat{
        var 
    $legs=4;
    }
    $tiddles=new Cat();
    echo 
    $tiddles->legs;
    ?>
    it gives me legs;
    am using WAMP version 1.7.2

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    If you are using PHP5 you need to replace var with public (or private or protected)

    PHP Code:
    <?php
    class Cat{
        public 
    $legs=4;
    }
    $tiddles=new Cat();
    echo 
    $tiddles->legs;
    ?>

  • #3
    New Coder
    Join Date
    Oct 2007
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thnxx it works now

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 96 Times in 94 Posts
    glad its working now, but for the record , `var` works fine in PHP5 though ideally you will be using public/private etc
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Actually var is supposed to become an alias of public in PHP6.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

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