Created
August 11, 2020 14:45
-
-
Save rajeshbakade65/701091fd5c61236205df9ef3beb66aef to your computer and use it in GitHub Desktop.
php self:: Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class books | |
{ | |
public static $bookId = 0; | |
public function updateBookInfo($id) | |
{ | |
self::$bookId = $id; | |
} | |
public function getBookId() | |
{ | |
return self::$bookId; | |
} | |
} | |
// object 1 | |
// before update | |
$objBooks = new books; | |
$objBooks->updateBookInfo(1); | |
echo $objBooks->getBookId(); | |
// object 2 | |
$newObjBook = new books; | |
echo $newObjBook->getBookId(); | |
$newObjBook->updateBookInfo(2); | |
// after update | |
echo $objBooks->getBookId(); | |
echo $newObjBook->getBookId(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment