Jump to content


PHP 5 -lets talk about this


7 replies to this topic

#1 Guest_contact_bogomil_*

  • Guests

Posted 25 April 2003 - 03:21 PM

Lession 1:

In PHP4 all the methods and variables in an Object can be accessed from outside the object - this can be rephrased as methods and variables are always public. PHP5 introduces 3 modifiers to control the access to variables and methods: Public, Protected and Private.

Public: The method/variable can be accessed from outside the class.

Private: Only methods in the same class can access private methods or variables.

Protected: Only methods in the same class or derived classes can access proteted methods or variables.



<?php
class foo {
  private $x;

  public function public_foo() {
    print("I'm public");
  }

  protected function protected_foo() {
    $this->private_foo(); //Ok because we are in the same class we can call private methods
    print("I'm protected");
  }

  private function private_foo() {
    $this->x = 3;
    print("I'm private");
  }
}

class foo2 extends foo {
  public function display() {
    $this->protected_foo();
    $this->public_foo();
    // $this->private_foo();  // Invalid! the function is private in the base class
  }
}

$x = new foo();
$x->public_foo();
//$x->protected_foo();  //Invalid cannot call protected methods outside the class and derived classes
//$x->private_foo();    //Invalid private methods can only be used inside the class

$x2 = new foo2();
$x2->display();
?>





#2 PHPlugin

    Advanced Member

  • Members
  • PipPipPip
  • 487 posts

Posted 26 April 2003 - 11:19 AM

Hi!

PHP 5 seems to be cool, when it's released.

Something confuses me a bit.

Code snippet:

class foo {
  private $x;

  public function public_foo() {
    print("I'm public");
  }
  

Let's have a look at 'private $x'.

Shouldn't it be written:

private var $x;

Cause you also DON'T write 'public public_foo();'.
(Missing the 'function'.)

Thanks!

#3 eduac

    Advanced Member

  • Members
  • PipPipPip
  • 218 posts

Posted 24 May 2003 - 12:15 AM

anybody here, knows when the php5 release can be available for us? :blink:

#4 Guest_kacaloy_*

  • Guests

Posted 26 July 2003 - 01:44 PM

Wow!

That's kool. PHP is now moving into a true OOP direction. Great!

#5 Guest_darkcarnival_*

  • Guests

Posted 07 August 2003 - 11:56 PM

i would love to have it too ill have to convince my host to upgrade once it come available.(i currently run on v4.3.1)

#6 Dr.Nabhan

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 17 August 2005 - 04:20 PM

Hello ..

in the classes the function var wouldn't work unless u have Choses the (E_STRICT)

In php5 - database there is a good new things like

-1 - using SimpleXML
-2- using SQLlite


in php4  connecting between php and XML was complicated somehow but in php5 the (DOM) was reprogrammed and connecting with  XML is more simple that lead to born the SimpleXML and u can make RSS in it.

SQLlite is a new DataBase engine and it is very simple and what make it special is that this database engine don't depend on  Client/server

that is some of the new things in php5 .

Thanx ..

#7 vijaybe2006

    Newbie

  • Members
  • Pip
  • 0 posts

Posted 07 November 2006 - 11:39 AM

Quote

i would love to have it too ill have to convince my host to upgrade once it come available.(i currently run on v4.3.1)

i want to learn php....i m start from...?
  and any ref site name which is usefull to me..

#8 Leibrockoli

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 07 July 2008 - 06:35 PM

Quote

Hi!

PHP 5 seems to be cool, when it's released.

Something confuses me a bit.

Code snippet:

class foo {
  private $x;

  public function public_foo() {
    print("I'm public");
  }
  

Let's have a look at 'private $x'.

Shouldn't it be written:

private var $x;

Cause you also DON'T write 'public public_foo();'.
(Missing the 'function'.)

Thanks!                   

You don't need to include var in declared variables anymore, just public, private, and protected.

However, they made it now so that var is the equivalent of public, as old PHP4 OOP would be using var for variables. This just made it simpler for PHP4 programmers.

Nor do you need to declare functions as one of the three also, you can still just write function.

class fake{
var $x;

function y(){
print $this->x;
}
}
would still work.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users