Skip to content

Instantly share code, notes, and snippets.

@rajeshbakade65
Created August 11, 2020 14:45
Show Gist options
  • Save rajeshbakade65/701091fd5c61236205df9ef3beb66aef to your computer and use it in GitHub Desktop.
Save rajeshbakade65/701091fd5c61236205df9ef3beb66aef to your computer and use it in GitHub Desktop.
php self:: Example
<?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