SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 31 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

emailer.php on line 42
and defined in C:\OOP with PHP5\Codes\ch1\class.emailer.php
on line 9

See the difference? If your class had no constructor method or a constructor with no
arguments, you can instantiate it with the above code.
Modifiers
You have seen that we used some keywords like private or public in our class. So
what are these and why do we need to use them? Well, these keywords are called
modifier and introduced in PHP5. They were not available in PHP4. These keywords
help you to define how these variables and properties will be accessed by the user of
this class. Let's see what these modifiers actually do.
Private: Properties or methods declared as private are not allowed to be called
from outside the class. However any method inside the same class can access them
without a problem. In our Emailer class we have all these properties declared as
private, so if we execute the following code we will find an error.
include_once("class.emailer.php");
$emobject = new Emailer("hasin@somewherein.net");
$emobject->subject = "Hello world";
?>
Chapter 2
[ 23 ]
The above code upon execution gives a fatal error as shown below:
Fatal error: Cannot access private property emailer::$subject
in C:\OOP with PHP5\Codes\ch1\class.


Pages:
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6