Jump to content

[SOLVED] oop newb, error message


Lodius2000

Recommended Posts

im working on learning oop through an online tutorial

 

its talking about public, proected and private right now and i am getting an error that doenst match what the tutorial says i should be getting

 

Fatal error: Cannot access private property person::$pinn_number in ...

 

instead i am getting

 

Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /Users/imaging/Desktop/oop/class_lib.php on line 10

 

heres my code

 

class_lib.php


<?php

class person {


var $name;

public $height;
protected $social_insurance;
private $pinn_number;



function __construct($persons_name) {

$this->name = $persons_name;

}

function set_name($new_name) {  
           
            $this->name = $new_name;       
           
      }

      function get_name() {

            return $this->name;

      }

}

?>

 

index.php



<?php include("class_lib.php"); 


$stefan = new person("Stefan Mischook");

echo "Stefan's full name: " . $stefan->get_name();

/*
Since $pinn_number was declared private, this line of code will generate an error. Try it out!
*/


echo "Tell me private stuff: " . $stefan->pinn_number;



?>

 

heres the tutorial but my code has been cut and pasted from there just to make sure i didnt have  typo

 

http://www.killerphp.com/tutorials/object-oriented-php/php-objects-page-3.php

 

whats the problem

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/131867-solved-oop-newb-error-message/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.