Archive for the ‘OOP’ Category

How to access variables or methods of the parent class in php

use the double colon(::) and parent keyword to access the variables or methods of the parent class in php

  1. class myparent {
  2. function myfunction() {
  3. echo "parent method";
  4. }
  5. }
  6.  
  7. class mychild extends myparent {
  8. function myfunc()[
  9. parent::myfunction();
  10. }
  11. }

, , , ,

No Comments


How to access Static variables in php

To access Static variables;

  1. class mystatic {
  2. private static $staticvar;
  3.  
  4. public static function staticmethod{
  5. return <strong>self::$staticvar</strong>;
  6. }
  7. }

, ,

No Comments


Difference between $this vs self in class using php

$this - use this if you are accessing a variable or method without static keyword within a class
self - use this if you are accessing a static variable or constant within a class

No Comments


Accessing Static Variable within Static method in a Class

Use self to access static variable or const within a class.
example:

  1. class static_class {
  2.  
  3.             private static static_variable = 'I am static ';
  4.             public static function getStaticVariable() {
  5.                  self::$static_variable;
  6.             }
  7. }

, , ,

No Comments



SetPageWidth