Quickupdate

  • Home
  • Top Trending
    • Top Android Apps
    • Top Ios Apps
  • Featured
  • About Us
  • Contact us
  • Privacy Policy and Disclaimer

Friday, 10 January 2020

Oops PHP : Access Modifires

 Developers     January 10, 2020     No comments   

There are 3 types of access modifiers.
public : public property or method can be accessed Form anywhere (This is by default)
protected : protected proerty can be accessed With in the class & child class which extending parent class
private : "private" property or method can be access ONLY in the class.


NOTE: if you want to Access a "Private Property" Which is only accessible inside the class, then for that,
first, you have to create a "Public function", Then access that "Public function" after creating an object.


<?php

class AccessModifiers
{

    public $name;
    protected $color;
    private $height;

    function get_protected($color)
    {
        return $this->color = $color;
    }
}

$a_Obj = new AccessModifiers();
echo $a_Obj->name = 'mango. <br>';

echo $a_Obj->get_protected("red");

?>

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

PHP Oops - Static Properties / Keword

 Developers     January 10, 2020     No comments   

1) there are many variations of static keyword
1) static method
2) static property
3) static closure (A CLOSURE is an anonymous function that can access variables imported from the outside scope without using any global variables.)
4) static variable
5) static as a class name

2) $this isn't accessible in these methods

3) IF you create a static property/method THen you don't have to create/instantiate a class. you can access without creating the object of a class.

4)if you declared a static property and you created obj of class, then you cannot access that property. (but you can access, Methods)
E.g:

<?php

  class StaticClassExample {
  public static function test() {
  echo "this is the static function";
  }
}

new StaticClassExample();
StaticClassExample::test();
?>

5) To access a static property use the class name, a double colon (::), and the property name
ClassName::staticPropName();

6) A class can have both static and non-static Properties. A static Property can be accessed from a METHOD in the SAME class using
the "self" keyword and double colon "(::)".

7) You can create 2 classes in One File

<?php
class StaticClassExample
{

    public static function test()
    {
        echo "this is the Static function.<br>";
    }

    public function testOne()
    {
        echo "This is the Normal function.<br>";
    }
}

StaticClassExample::test();
// $a = new StaticClassExample();
// $a->testOne();


class NewClass extends StaticClassExample
{

    public function get_value_from_static()
    {
        echo parent::testOne();
    }
}

$b = new NewClass();
$b->get_value_from_static();
?>

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Thursday, 9 January 2020

Oops PHP : __constructors()

 Developers     January 09, 2020     No comments   

in short: Once the Object created of class Constructor Will be called Automatically.

Example:

<?phpclass BaseClass {
    function 
__construct() {
        print 
"In BaseClass constructor\n";
    }
}

class 
SubClass extends BaseClass {
    function 
__construct() {
        
parent::__construct();
        print 
"In SubClass constructor\n";
    }
}

class 
OtherSubClass extends BaseClass {
 
// inherits BaseClass's constructor
}

// In BaseClass constructor
$obj = new BaseClass();// In BaseClass constructor
// In SubClass constructor

$obj = new SubClass();// In BaseClass constructor
$obj = new OtherSubClass();?>
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

Popular Posts

  • How to upload the existing folder on GitHub Or GitLab?
    These are the steps to upload the existing folder on GitHub Or GitLab. Whenever you want to push your existing folder to git or GitHub you m...

Categories

  • FAANG (2)
  • Javascript (6)
  • Node (1)
  • Project Management (1)
  • React (9)
  • SQL (1)
  • Testing (1)

Blog Archive

  • January 2023 (1)
  • January 2022 (1)
  • November 2021 (3)
  • October 2021 (3)
  • August 2021 (1)
  • July 2021 (7)
  • June 2021 (12)
  • February 2021 (1)
  • January 2021 (1)
  • January 2020 (3)
  • August 2019 (3)