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 adds an image in web page?
<div> <img> <span><img src="http://coursesweb.net/imgs/webcourses.gif" width="191" height="63" alt="Courses-Web" />
Which of these CSS codes displays the text oblique?
font-style: italic; text-decoration: underline; font-weight: 500;#id {
font-style: italic;
}
Click on the jQuery function used to hide with animation a HTML element.
click() hide() show()$(document).ready(function() {
$(".a_class").click(function(){ $(this).hide("slow"); });
});
Click on the correctly defined function in PHP.
fname function() {} function fname() {} function $fname() {};function fname($a, $b) {
echo $a * $b;
}