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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: istvan at palocz dot hu
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 01:01:35 2025 UTC