- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8k
          PhpToken::is(): switch @param to typehint
          #16218
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
        
      
            DanielEScherzer
  wants to merge
  1
  commit into
  php:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
DanielEScherzer:token-is-typehint
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to be able to add the type declaration, the custom parameter parsing should be consistent with the "real" ZPP if it contained
Z_PARAM_LONG()which ultimately runs thezend_parse_arg_long_weakfunction for type juggling.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I don't really understand what you're saying - is the typehint not allowed because integer-like strings are not cast to integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what I really wanted to say is that ideally, a native type declaration should only be added when ZPP behaves exactly how the same type declaration would be treated in userland. However, the validation in debug mode only checks whether the function doesn't throw when in fact it should based on the type declaration: https://github.com/php/php-src/blob/0b3684c48e8dd1b960bd179f7957d69d0b882ea2/Zend/zend_vm_execute.h#L2043
PhpToken::is()always parses parameters strictly, so it rather throws when it shouldn't (e.g. when a float or a numeric string is passed to it), so it slightly differs from what a userlandint|string|arraytype check would do. That's why in the past we changed a lot ofZ_PARAM_ZVAL()calls to more preciseZ_PARAM_*calls, but I just cannot remember whether it was strictly necessary to do, or if we just did it because it was better for consistency (since thezend_internal_call_arginfo_violationcheck doesn't always find the issue). @Girgias could you please refresh my mind? Do you thinkPhpToken::is()can have the native type declaration?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huuuum, we have been using native types for GMP functions, but it does handle the deprecations for
nulland weak type semantics.I know we don't use native types explicitly for
method_existsandproperty_existsso that we can by-pass known wrong values ofintandbool. (and maybe we should revisit this for those cases.)So I think you are correct @kocsismate in that we don't do it for consistency with weak mode.