Answer the question
In order to leave comments, you need to log in
What to read to understand the OPP syntax in PHP?
Good afternoon toasters!
I came across an article
habrahabr.ru/post/143317
Since I am self-taught in PHP, I do not understand such moments in syntax:
$jsonError->error='No function called';
return $this.
Answer the question
In order to leave comments, you need to log in
Forums and documentation are good, but if you are not familiar with OOP and are just starting out, it's better to read books. To comprehend the basics, I recommend:
PHP 5/6 Tutorial, Kuznetsov, Simdyanov
PHP 5 (original)
If you do not like to read big thick books, then you can just read the chapter on OOP in any of these books.
Regarding c $jsonError->error='No function called';
, PHP implicitly creates a stdClass object in this case . Doing so is not recommended as PHP will issue a warning:
Warning: Creating default object from empty value .
It's better to write like this:
<?php
header('Content-type: text/html; charset=UTF-8');
if (count($_REQUEST)>0){
// ...
}else{
$jsonError = new stdClass();
$jsonError->error = 'No function called';
echo json_encode($jsonError);
}
?>
return $this
- this is done to implement chains of calls (Method Chaining). Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question