php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76090 Use self instead of class name in example
Submitted: 2018-03-13 14:25 UTC Modified: 2018-03-13 23:12 UTC
From: istvan at palocz dot hu Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.3 OS:
Private report: No CVE-ID: None
 [2018-03-13 14:25 UTC] istvan at palocz dot hu
Description:
------------
---
From manual page: http://www.php.net/closure.bind
---
Example 1 contains a following code:

<?php
$cl1 = static function() {
    return A::$sfoo;
};
?>

My suggestion:
<?php
$cl1 = static function() {
    return self::$sfoo;
};
?>
This example show why use bind(), but A:: works without bind(). 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-13 14:44 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: Documentation problem +Package: Scripting Engine problem
 [2018-03-13 14:44 UTC] requinix@php.net
Actually it wouldn't work because $sfoo is private. https://3v4l.org/iLVpZ

A::$sfoo demonstrates that the code can access the property member, while self::$sfoo would demonstrate that the code is running from "within" the A class. Both mean the same thing. But the second callback already shows the "within the A class" aspect by using $this, so I think having A::$sfoo being clearer about accessing members is good.

Does that make sense? Agree or disagree?
 [2018-03-13 15:27 UTC] istvan at palocz dot hu
-Status: Feedback +Status: Closed
 [2018-03-13 15:27 UTC] istvan at palocz dot hu
Ok, I missed the private keyword.

Agree
 [2018-03-13 23:12 UTC] cmb@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 04:01:38 2024 UTC