php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76117 uopz flags is NOT for classes, but methods
Submitted: 2018-03-20 04:03 UTC Modified: 2020-08-13 13:55 UTC
From: Andy_Schmidt at HM-Software dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 7.2.3 OS: any
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Andy_Schmidt at HM-Software dot com
New email:
PHP Version: OS:

 

 [2018-03-20 04:03 UTC] Andy_Schmidt at HM-Software dot com
Description:
------------
---
From manual page: http://www.php.net/function.uopz-flags
---
The manual incorrectly states: "Get or set flags on function or class". 

This implies to the reader that either the flags of a standalone function, or the flags of the class itself (such as "final class {}") can be queried or manipulated.

In reality with version UOPZ 5.02 one can only reference a function or a class::method! One simply cannot omit the function name (e.g., making it NULL, or '' - it can't even be '__construct')

The correct text shoud read:
"Get or set flags on function or class method"
...
"Get or set the flags on a method or function entry at runtime"
...
function
The name of the function or method



Test script:
---------------
final class MyClass { function mymethod() {} };
var_dump( ( new ReflectionClass( 'MyClass') )->isFinal() );

if ( !defined( 'ZEND_ACC_FETCH' ) )
	define( 'ZEND_ACC_FETCH', PHP_INT_MAX );

// Works:
var_dump( uopz_flags( 'MyClass', 'mymethod' , ZEND_ACC_FETCH ) );

// Fails:
var_dump( uopz_flags( 'MyClass', '' , ZEND_ACC_FETCH ) );
var_dump( uopz_flags( 'MyClass', NULL , ZEND_ACC_FETCH ) );



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-20 12:36 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2018-03-20 12:36 UTC] cmb@php.net
Please try:

    <?php
    final class MyClass { function mymethod() {} };
    var_dump( ( new ReflectionClass( 'MyClass') )->isFinal() );
    uopz_flags(MyClass::class, null, 0);
    var_dump( ( new ReflectionClass( 'MyClass') )->isFinal() );

This should print:

    bool(true)
    bool(false)
 [2018-03-20 15:18 UTC] Andy_Schmidt at HM-Software dot com
-Status: Feedback +Status: Assigned
 [2018-03-20 15:18 UTC] Andy_Schmidt at HM-Software dot com
Result:

PHP Fatal error:  Uncaught InvalidArgumentException: 
unexpected parameter combination, 
expected (class, function, flags) or (function, flags)
Stack trace: #0: uopz_flags('MyClass', NULL, 0)
 [2018-03-20 17:43 UTC] cmb@php.net
-Status: Assigned +Status: Feedback
 [2018-03-20 17:43 UTC] cmb@php.net
Thanks for testing.  However, my test script works for me on
Windows with PHP 5.6 with UOPZ 2.0.7 and PHP 7.1 and 7.2 with UOPZ
5.0.2, which is to be expected from looking at the relevant
code[1].

The InvalidArgumentException would be thrown, though, if an yet
undefined class would be passed as first parameter to
uopz_flags().  Is there perhaps an issue with OPcache?  Note that
UOPZ should be loaded before OPcache.

[1] <https://github.com/krakjoe/uopz/blob/v5.0.2/uopz.c#L530>
 [2018-03-20 19:32 UTC] Andy_Schmidt at HM-Software dot com
-Status: Feedback +Status: Assigned
 [2018-03-20 19:32 UTC] Andy_Schmidt at HM-Software dot com
No Opcode active. I even disabled WinCache and xdebug extensions and retestet. In addition, I moved the uopz extension to be first one .ini file.

Result remains:
PHP Fatal error:  Uncaught InvalidArgumentException: unexpected parameter combination, expected (class, function, flags) or (function, flags) 
Stack trace:
#0 E:\Hosted Sites\wwwroot\anamera_v2\test\syntax.php(6): uopz_flags('MyClass', NULL, 0)
#1 {main}

To me, the message does NOT indicate that "class" does not exist, it seems to state that the parameter signature doesn't match one of the two permitted variations.

This is further supported by the fact that THIS will work just fine:

var_dump( uopz_flags(MyClass::class, 'mymethod', 0) );

If the problem was an absent MyClass, then the combination MyClass::mymethod would also have failed.

So - as long as a method parameter is not left NULL, the uopz_flags function will work as expected.
 [2018-03-20 19:40 UTC] Andy_Schmidt at HM-Software dot com
In fact, lookin at YOUR code snippet you sent me, it does seem to permit either an object or string for the FIRST parameter (scope), and ONLY a string for the SECOND parameter (prop)? If the second parameter is NOT a string, then the error message will be logged to the php error log:

!scope || !prop || !value ||
(Z_TYPE_P(scope) != IS_OBJECT && Z_TYPE_P(scope) != IS_STRING) ||
Z_TYPE_P(prop) != IS_STRING)
 [2018-03-20 22:08 UTC] cmb@php.net
-Assigned To: cmb +Assigned To: krakjoe
 [2018-03-20 22:08 UTC] cmb@php.net
I was assuming "normal" typing, not strict typing.  In the latter
case passing NULL as second argument to uopz_flags() would indeed
trigger an InvalidArgumentException.

Joe, could you please clarify whether retrieving and changing
attributes of a class via uopz_flags() is supposed to work by
passing an empty string as second argument?
 [2020-08-13 13:55 UTC] cmb@php.net
-Status: Assigned +Status: Closed -Assigned To: krakjoe +Assigned To: cmb
 [2020-08-13 13:56 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=7cd4445be975bd28512cd2fe3b5016489901f73c
Log: Fix #76117: uopz flags is NOT for classes, but methods
 [2020-08-14 02:25 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=09670b2b494436e8de26f2fdc184ece78257cb4b
Log: Fix #76117: uopz flags is NOT for classes, but methods
 [2020-12-30 11:59 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=7001e90cc60acffe3579dc9d19de0e675e75bc7e
Log: Fix #76117: uopz flags is NOT for classes, but methods
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 21:01:30 2024 UTC