PHP code example of simones / dotnot
1. Go to this page and download the library: Download simones/dotnot library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
simones / dotnot example snippets
// stdClass + array
dotnot((object) [
'author' => [
'name' => 'Simone Salerno'
]
])->get('author.name')
// Custom class, with getter method
class Author {
public function getAuthorName() {
return 'Simone Salerno';
}
}
// this looks for a method named "get" . ucfirst($getter)
dotnot(new Author)->get('authorName')
// when it can't resolve the path, it throws an exception
// so you should catch it or test for existence
dotnot(new Author)->get('foo') // throws DotNotException
//or
$dotnot = dotnot(new Author);
if ($dotnot->has('foo')) {
// do some work...
}
// it also works with numeric indexes
dotnot([
'people' => [
0 => (object) [
'author' => new Author
]
]
])->get('people.0.author.authorName')