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 3 of 3

Thread: oop problem

  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    28
    Thanks
    3
    Thanked 4 Times in 4 Posts

    oop problem

    I am just learning oop so this may be obvious but I can't see what is wrong here.
    PHP Code:
    class board {
        function 
    __construct($fen){
            
    $ranks array_reverse (explode("/"$fen));
        }
        function 
    get_rank($rank){
            return 
    $this->ranks[$rank];
        }
    };

    $grid = array(1=> new board('xx/xx/xx'), new board('xx/xx/xx'), new board('xx/xx/xx'));

    echo 
    $grid[1]->get_rank(1); //why does this return nothing? 
    Thanks in advance for any help.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    PHP Code:
        function __construct($fen){ 
            
    $ranks array_reverse (explode("/"$fen)); 
        } 
    PHP doesn't use variable masking, so you have to use $this->ranks in order to store it. You should declare the variable though with private $ranks in order to prevent errors from you're accessor.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    28
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Thanks Fou, I knew it would be something obvious since I spent an hour or so trying to fix it.


  •  

    Posting Permissions

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