What is the symbol for calling class methods in php

WBOY
Release: 2023-03-15 11:22:02
Original
3276 people have browsed it

In PHP, the symbol for calling class methods is "->"; the "->" symbol is an inserted dereference operator, which is used to call member properties and methods of an object. It is called by a reference. The method of the subroutine that passes parameters, the syntax is "class name->method".

What is the symbol for calling class methods in php

The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer

What are the symbols for calling class methods in php

'- >' symbol is the "infix dereference operator". In other words, it is a method that calls a subroutine whose parameters are passed by reference (among other things, of course). As we mentioned above, when calling PHP functions, most parameters are passed by reference. The '->' functions in PHP are just like they are in Perl or C. The following is a simple dereference example:

echo $x->def(); # The output

example is as follows:

First, in a tool Declare a class in the .php file:

<?php
  class tool {
  function say(){
  $result="Hello,World";
  return $result;
  }
}
Copy after login

Call the method in the above class in another file main.php:

<?php
  require_once &#39;tool.php&#39;;
  $tool=new tool();
  $content=$tool->say();
  echo $content;
?>
Copy after login

Recommended learning: "PHP Video Tutorial

The above is the detailed content of What is the symbol for calling class methods in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template