0% found this document useful (0 votes)
78 views14 pages

PHP 5 Disable Strict Standards Error: 'Display - Errors' '0'

The document discusses various object oriented programming concepts in PHP including: 1. Classes, objects, and instantiating objects using the new keyword. It provides an example class with a method. 2. Constructor and destructor methods, and calling parent methods. An example demonstrates these. 3. Class constants that do not require a $ and remain unchanged. An example class demonstrates defining and accessing a constant. 4. Inheritance using the extends keyword allows a child class to inherit from a parent class. An example inheritance hierarchy is provided.

Uploaded by

Anil Rawat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views14 pages

PHP 5 Disable Strict Standards Error: 'Display - Errors' '0'

The document discusses various object oriented programming concepts in PHP including: 1. Classes, objects, and instantiating objects using the new keyword. It provides an example class with a method. 2. Constructor and destructor methods, and calling parent methods. An example demonstrates these. 3. Class constants that do not require a $ and remain unchanged. An example class demonstrates defining and accessing a constant. 4. Inheritance using the extends keyword allows a child class to inherit from a parent class. An example inheritance hierarchy is provided.

Uploaded by

Anil Rawat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

http://php.net/manual/en/language.oop5.

php
PHP 5 disable strict standards error
ini_set('display_errors', '0'); error_reporting(E_ALL | E_STRICT); Do you want to disable error reporting, or just prevent the user from seeing it? Its usually a good idea to log errors, even on a production site. # don't show any errors... # ...but do log them

They will be logged to your standard system log, or use the error_log directive to specify exactly where you want errors to go. For no errors. error_reporting(0); or for just not strict error_reporting(E_ALL ^ E_STRICT); and if you ever want to display all errors again, use error_reporting(-1);

Does static method in PHP have any difference with non-static method?
class t { public function tt() { echo 1; } } t::tt(); See?The non-static function can also be called at class level.So what's different if I add a statickeyword before public?

Except that, if you try to use $this in your method, like this : class t { protected $a = 10; public function tt() { echo $this->a; echo 1; } }

t::tt(); You'll get a Fatal Error when calling the non-static method statically : Fatal error: Using $this when not in object context in ...\temp.php on line 11 i.e. your example is a bit too simple, and doesn't really correspond to a real-case ;-) Also note that your example should get you a strict warning (quoting) : Calling non-static methods statically generates an E_STRICT level warning. And it actually does (At least, with PHP 5.3) : Strict Standards: Non-static method t::tt() should not be called statically in ...\temp.php on line 12 1 So : not that good ;-)

Still, statically calling a non-static method doesnt't look like any kind of good practice (which is probably why it raises a Strict warning), as static methods don't have the same meaning than non-static ones : static methods do not reference any object, while non-static methods work on the instance of the class there're called on.

I didn't get a strict warning,php.ini setting is error_reporting = E_ALL

this is because E_ALL doesn't include E_STRICT -- seephp.net/manual/en/errorfunc.constants.php which states that E_ALL is " except of level E_STRICT in PHP < 6"

2
Oh,I've changed to error_reporting = E_ALL & E_STRICT,still no warning..PHP5.3.0

That's probably because you don't need to use E_ALL & E_STRICT, but E_ALL | E_STRICT (i.e you needE_ALL + E_STRI version of PHP this started to raise an E_STRICT error_reporting display_errors = = E_ALL & ~E_NOTICE ; Show all errors except for notices Off ; Print out errors (as a part of the output)

PHP Class Object


http://www.roseindia.net/tutorial/php/phpoop/index.html http://php.net/manual/en/language.oop5.php
PHP Class Object:

In object oriented programming a class can be an abstract data type, blue print or template. You could consider the name of a class as noun like name of a person, place or thing. For example Fruit is a class, where apple, orange are the object of this class. Object is the instantiate of a class. A class consists of a member variable and methods. In PHP we need to declare the access specifies (public, private, or protected) separately for PHP Object Class Example: <?php class A{ // method or function declaration public function disp(){ echo "Inside the class<br/>"; }} $a=new A(); $a->disp(); A::disp(); ?> Output:

Inside the class Strict Standards: Non-static method A::disp () should not be called statically in C:\xampp\htdocs\Cora\opps\examp1.php on line 11 Inside the class
Explanation: In the above programming we create a class named A, it has a publically declared function disp(), on the

outer side of the class we instantiate the object $a, we call the function disp with -> operator. Any class can access it's member using :: operator.

PHP Constructor and Destructor


Like other OOP based languages PHP also supports constructor method for classes. As any other language's constructor method, in PHP constructor method is called for every object creation. We can call parent's constructor method using parent::__construct() from the child constructor. PHP also supports destructor like C++. This method is called as soon as the references of the object are removed or if we destroy the object . This feature has been included in PHP 5. Like constructor method we can call the destructor method of parent class by parent::__destruct(). The destructor is being called any how, means even after executing the exit() code destructor method could be called. PHP Constructor & Destructor Example: <?php class ParentClass { function __construct() {print "In parent class <br/>";} } class ChildClass extends ParentClass { function __construct() {

parent::__construct(); print "In child class"; } } $obj1=new ParentClass(); $obj2=new ChildClass();?> Output: In parent class In parent class IIn child class --------OR---------<?php class ParentClass { function ParentClass() {print "In parent class <br/>";} }

class ChildClass extends ParentClass { function ChildClass()

{ parent::__construct(); print "In child class"; } } $obj1=new ParentClass(); $obj2=new ChildClass(); ?> Example: <?php class ParentClass{ function __construct(){ print "In parent class <br/>"; } function __destruct(){ print "Parent Class Destructor called<br/>"; } } class ChildClass extends ParentClass{ function __construct(){

parent::__construct(); print "In child class<br/>"; } function __destruct(){ print "Child Class Destructor called<br/>"; } } $obj1=new ParentClass(); $obj2=new ChildClass(); ?>

Output: In parent class In parent class In child class Child Class Destructor called Parent Class Destructor called

PHP Class Constant


PHP Class Constants: Sometimes we need to have constant values in our program which remains same through and through. We do not need to put a $ sign before the constant to use or to declare it. The value of the constant should remain unchanged that means it must be a constant expression.

Example: <?php class A { const newValue="Constant value does not consist $ sign"; function display() { echo self::newValue."\n"; } } $a=new A(); $a->display(); ?> Output: Constant value does not consist $ sign Explanation: In the above example there is a single class declaration named A. Outside of this class

Or <?php ini_set('display_errors', '0'); # don't show any errors...

error_reporting(E_ALL | E_STRICT); # ...but do log them

class A

const newValue="Constant value does not consist $ sign<br/>";

function display()

echo self::newValue."\n";

$a=new A();

$a->display(); A::display(); ?>

Constant value does not consist $ sign Constant value does not consist $ sign

PHP Create Instance

Create an Instance: In OOPs programming we need to instantiate each object. In the following example we create two classes A and B. To access variables of the class we should use self keyword following with double colon sign. When we need to access the variables of a class from an object we use -> operator sign. To instantiate an object we need to use new operator as: object-name=new class-name(); Following example is based on these concept, go through the example and run it on your computer, you will come to know how it works: How to Create PHP Instance with Example: <?php class A { public static $one; public function set($one){ self::$one=$one; } public function get(){ echo "Value of variable is:".self::$one;} } class B { public function disp(){

echo "<br/>Inside Class B";} } $a=new A(); $a->set(12); $a->get(); $class='B'; $a=new $class(); $a->disp(); ?>

Output: Value of variable is:12 Inside Class B

PHP Inheritance Class


Inheritance in PHP: Inheritance is a property of Object Oriented Programming, PHP also supports this principle in its programming as object model. With the help of this property classes and objects get more flexibility, scalability in programming At the same time we must keep in our mind that when we should not use the inheritance. We must not use inheritance when we have only different values in classes, we must use the inheritance when the structure and the behavior are different. It is always advisable that we must give preference to object composition over inheritance.

In the following example we will come to know how a class could be declared as a child class of another class using extends keyword. PHP Inheritance Example: <?php class One { public function printItem($string) { echo 'This argument is passing from '.$string.'<br/>'; } } class Two extends One { } $baseObj=new One(); $childObj=new Two(); $baseObj->printItem("Base"); $childObj->printItem("Child"); ?>

Output:

This argument is passing from Base This argument is passing from Child

PHP Mutator Accessor


PHP Mutator and Accessor Methods: In object-oriented programming, the mutator method (also called "setter") is used to initialize the member variables of a class. According to the encapsulation principle the variables of the class are declared as private to protect and can be modified by a public declared function. On the other hand accessor methods (or getter) are used to get the values of the private data member. These methods can be implemented on non-object-oriented programming language as well. In this case we have to pass the address (reference) of the variable. PHP Mutator Method Example: <?php class One{ private $string; public function mutator($arg){ $this->string=$arg;} public function accessor(){ echo "Value is: ".$this->string;}} $one=new One(); $one->mutator("roseindia"); $one->accessor(); ?>

Output: Value is: roseindia

PHP Autoload
PHP Autoloading Classes: It is very common in PHP programming that we need to write long listing of files which has to be include in a single file. It is indeed a hectic job for each PHP programmer. But with the advent of PHP 5.0, this is not necessary anymore. We can define an _autoload function to call automatically the class/interface which has not been defined yet.

PHP Autoload Class Example: <?php function _autoload($classname){ require_once $classname.'.php'; } $obj=new mysqli(); ?>

No Output will be generated

You might also like