Static variable changes before call?

WBOY
Release: 2023-03-02 13:32:01
Original
955 people have browsed it

<code>class Test {
    static $name='app';
    static $age=30;
}</code>
Copy after login
Copy after login
<code>$name=Test::$name;
echo $name;</code>
Copy after login
Copy after login

How to change the value of $name before returning in Test?

Reply content:

<code>class Test {
    static $name='app';
    static $age=30;
}</code>
Copy after login
Copy after login
<code>$name=Test::$name;
echo $name;</code>
Copy after login
Copy after login

How to change the value of $name before returning in Test?

If a static variable is changed by you, why would it be called a static variable?

Why do you need to change the value of a static variable before using it? The original intention of static variable setting is to serve as an initial value for calling. You can reassign the static variable and assign it dynamically before using this value

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!