Welcome Guest, Not a member yet? Register   Sign In
PHP5 OOP Standards
#4

[eluser]Yorick Peterse[/eluser]
Public stuff : Can be used outside the class itself

Code:
<?php
class class_1 {
  public var $foo = "foo";
}

$class = new class_1();
echo $class->foo; // Prints foo

?>

Private stuff : Can only be used in the class itself

Code:
<?php
class class_1 {
  private var $foo = "foo";
}

$class = new class_1();
echo $class->foo; // Returns an error

?>

Protected : Can be used outside the class, but with limitations

Code:
<?php
class class_1 {
  private var $foo = "foo";
}

// This will not work
$class = new chass_1();
echo $class->foo;

// However this will
class class_2 extends class_1 {
  function foo() {
    echo $this->foo; // Prints foo
  }
}

?>


Messages In This Thread
PHP5 OOP Standards - by El Forum - 06-18-2009, 07:25 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 07:34 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 07:53 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 07:54 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 07:54 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 07:56 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 08:00 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 08:02 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 08:04 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 08:07 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 08:21 AM
PHP5 OOP Standards - by El Forum - 06-18-2009, 12:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB