PHP Snippet 1:
public function withAttribute($name, $value)
{
$clone = clone $this;
$clone->attributes->set($name, $value);
return $clone;
}
PHP Snippet 2:
/*
* Slim/Http/Request.php
*/
public function withAttribute($name, $value)
{
$this->attributes->set($name, $value);
return $this;
}
PHP Snippet 3:
<?php
/* code taken from - https://www.tutorialspoint.com/php/php_object_oriented.htm*/
class Book {
var $price;
var $title;
function setPrice($par){
$this->price = $par;
}
function getPrice(){
return $this->price;
}
function setTitle($par){
$this->title = $par;
}
function getTitle(){
return $this->title;
}
}
class CopyBook {
var $price;
var $title;
function setPrice($par){
$clone = clone $this;
$clone->price = $par;
}
function getPrice(){
return $this->price;
}
function setTitle($par){
$clone = clone $this;
$clone->title = $par;
}
function getTitle(){
return $this->title;
}
}
$pp = new Book;
$pp->setTitle('Perter Pan');
$pp->setPrice(25);
$cpp = new CopyBook;
$cpp->setTitle('Peter Pan');
$cpp->setPrice(25);
var_dump($pp);
var_dump($cpp);
?>
PHP Snippet 4:
object(Book)#1 (2) {
["price"]=>
int(25)
["title"]=>
string(10) "Peter Pan"
}
object(CopyBook)#2 (2) {
["price"]=>
NULL
["title"]=>
NULL
}
PHP Snippet 5:
$request = $request->withAttribute('username','XXXXXX');
return $next($request, $response);