PHPself: $ abc. What if $ abc is a patchwork variable?

Source: Internet
Author: User
{Code...} Errors: set (& #039; system & #039;); echoself: $ error_message error.
class Errors extends Object{    public static $message, $code;    const SYSTEM_CODE = 'system';    const SYSTEM_MESSAGE = 'system error';            public static function set($code, $params = [])    {        $error_code = strtoupper($code) . '_CODE';        $error_message = strtoupper($code) . '_MESSAGE';        echo self::$error_message;    }}

Errors: set ('system ');
Echo self: $ error_message error.

Reply content:
class Errors extends Object{    public static $message, $code;    const SYSTEM_CODE = 'system';    const SYSTEM_MESSAGE = 'system error';            public static function set($code, $params = [])    {        $error_code = strtoupper($code) . '_CODE';        $error_message = strtoupper($code) . '_MESSAGE';        echo self::$error_message;    }}

Errors: set ('system ');
Echo self: $ error_message error.

The following content is found by @ Tranch, a friend of mine.
I just transferred it.

There are two methods:
The first is:


  

constantFunction Description

The other is


   getConstant($key);

Echo self: {$ error_message}

I don't quite understand what it means,...
// Why?
Echo self: $ error_message;
// Why not write this?
Echo $ error_message;

Your $ error_message is not a class attribute. Of course, an error is returned. You can directly echo $ error_message. That is not a class attribute.

Try adding {}

For example

class A{    public $attr_a = 'value_a';}$t=new A();$attr = 'attr_a';echo $t->{$attr};

I only tried to reference common variables, static variables, and mobile phones. I tried it myself.

Write in this way
Echo constant ('self: '. $ error_message );

echo self::$error_message;

Change

echo $error_message;

$ Error_message is not a static variable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.