To
chain a static and a public method through class name, for example:
className::staticMethod()->publicMethod()
The instance of the className must be returned in the staticMethod, using "
return new self" .
- Code example:
<?php
class clsShow {
public static $url;
public static function setData(){
self::$url = 'https://coursesweb.net/';
return new self;
}
public function show(){
echo self::$url;
}
}
// accessing show() method after setData()
clsShow::setData()->show(); // https://coursesweb.net/
• To this page:
PHP Method Chaining it is a lesson with more details and examples about chaining multiple methods.
Daily Test with Code Example
HTML
CSS
JavaScript
PHP-MySQL
Which tag is used to include external CSS file in web page?
<body> <script> <link><link href="/templ/style.css" rel="stylesheet" type="text/css" />
Which CSS property sets the text size?
font-weight text-decoration font-sizeh2 {
font-size: 1em;
}
Indicate the JavaScript property that can add HTML code into an element.
text value innerHTMLdocument.getElementById("someID").innerHTML = "HTML content";
Click on the function that returns the number of characters of a string in PHP.
count() strlen() stristr()$str = "http://CoursesWeb.net/";
$nr_chr = strlen($str);
echo $nr_chr; // 22