Results 1 to 2 of 2

Thread: PHP classes

  1. #1

    PHP classes

    Hi, I was wondering if php's member functions and variables have identifiers like C/C++ to prevent them from being accessed outside the class.

    so what is a way to the following in php?

    class kaveh
    private var $myVar;


    $obj = new kaveh();
    $obj->$myVar; //ERROR

  2. #2
    Join Date
    Aug 2002
    USA, Madison, Wisconsin
    The Zend Engine 2.0 introduces private member variables. Note that for performance reasons no error message is emitted in case of an illegal access to a private member variable.
    For more information visit

    PHP Code:
    class MyClass {
    $Hello "Hello, World!\n";

    printHello() {

    MyClass2 extends MyClass {
    printHello() {
    MyClass::printHello(); /* Should print */
    print $this->Hello;    /* Shouldn't print out anything */

    $obj = new MyClass();
    $obj->Hello;  /* Shouldn't print out anything */
    $obj->printHello(); /* Should print */

    $obj = new MyClass2();
    $obj->Hello;  /* Shouldn't print out anything */
    Professional web developer

Posting Permissions

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