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 = 'http://coursesweb.net/';
    return new self;
  }

  public function show(){
    echo self::$url;
  }
}

// accessing show() method after setData()
clsShow::setData()->show();             // http://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 renders as emphasized text, displaying the text oblique?
<strong> <pre> <em>
<p>Web development courses: <em>CoursesWeb.net</em></p>
Which CSS property defines the space between the element border and its content?
margin padding position
h3 {
  padding: 2px 0.2em;
}
Click on the method which returns the first element that matches a specified group of selectors.
getElementsByName() querySelector() querySelectorAll()
// gets first Div with class="cls", and shows its content
var elm = document.querySelector("div.cls");
alert(elm.innerHTML);
Indicate the PHP variable that contains data from a form sent with method="post".
$_SESSION $_GET $_POST
if(isset($_POST["field"])) {
  echo $_POST["field"];
}
Chaining Static and Public Methods in PHP

Last accessed pages

  1. Difference between two Dates - Time and Date (1370)
  2. Keep data in form fields after submitting the form (7674)
  3. Check the file type before Upload (7004)
  4. Creating objects in ActionScript (6799)
  5. Add Pause in JavaScript script (8514)

Popular pages this month

  1. Qwop (4080)
  2. Get Attribute (ID, Class, Name, Title, Src) with jQuery (2264)
  3. Get the value of the selected /checked checkboxes in a form (1751)
  4. Drag Racer V3 (1520)
  5. Flash Games - Free online Games (1235)