php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80651 [ZH] Example #1 chinese language
Submitted: 2021-01-21 03:30 UTC Modified: 2021-01-21 10:34 UTC
From: super at rongsp dot com Assigned:
Status: Closed Package: Translation problem
PHP Version: Irrelevant OS: windows10
Private report: No CVE-ID: None
 [2021-01-21 03:30 UTC] super at rongsp dot com
Description:
------------
---
From manual page: https://php.net/language.oop5.static
---

From https://www.php.net/manual/zh/language.oop5.static.php


<?php
class Foo
{
    public static $my_static = 'foo';

    public function staticValue() {
        return self::$my_static;
    }
}

class Bar extends Foo
{
    public function fooStatic() {
        return parent::$my_static;
    }
}


print Foo::$my_static . "\n";

$foo = new Foo();
print $foo->staticValue() . "\n";
print $foo->my_static . "\n";      // Undefined "Property" my_static 

print $foo::$my_static . "\n";
$classname = 'Foo';
print $classname::$my_static . "\n"; // As of PHP 5.3.0

print Bar::$my_static . "\n";
$bar = new Bar();
print $bar->fooStatic() . "\n";
?>
   </programlisting>
  </example>

  <example>
   <title>静态方法示例</title>
    <programlisting role="php">
<![CDATA[
<?php
class Foo {
    public static function aStaticMethod() {
        // ...
    }
}

Foo::aStaticMethod();
$classname = 'Foo';
$classname::aStaticMethod(); // 自 PHP 5.3.0 起
?>


--------------------------
   </programlisting>
  </example>

  <example>
   <title>静态方法示例</title>
    <programlisting role="php">
<![CDATA[
--------------------------

Test script:
---------------
<?php
class Foo
{
    public static $my_static = 'foo';

    public function staticValue() {
        return self::$my_static;
    }
}

class Bar extends Foo
{
    public function fooStatic() {
        return parent::$my_static;
    }
}


print Foo::$my_static . "\n";

$foo = new Foo();
print $foo->staticValue() . "\n";
print $foo->my_static . "\n";      // Undefined "Property" my_static 

print $foo::$my_static . "\n";
$classname = 'Foo';
print $classname::$my_static . "\n"; // As of PHP 5.3.0

print Bar::$my_static . "\n";
$bar = new Bar();
print $bar->fooStatic() . "\n";
?>


<?php
class Foo {
    public static function aStaticMethod() {
        // ...
    }
}

Foo::aStaticMethod();
$classname = 'Foo';
$classname::aStaticMethod(); // 自 PHP 5.3.0 起
?>



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-21 10:34 UTC] cmb@php.net
-Summary: document : Example #1 chinese language +Summary: [ZH] Example #1 chinese language -Package: Documentation problem +Package: Translation problem
 [2021-02-01 08:30 UTC] jhdxr@php.net
Automatic comment on behalf of jhdxr
Revision: http://git.php.net/?p=doc/zh.git;a=commit;h=abd61b44f3ed40f4f840a70a2abe2af9ef6209fe
Log: sync with en. fix #80651
 [2021-02-01 08:30 UTC] jhdxr@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC