Skip to content

Instantly share code, notes, and snippets.

@anjesh
Created August 14, 2017 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anjesh/55d60791bc96467fd9c17de6e8b21e8e to your computer and use it in GitHub Desktop.
Save anjesh/55d60791bc96467fd9c17de6e8b21e8e to your computer and use it in GitHub Desktop.
Notes taken during php source exploration to identify weird error message

Running VLD for opcodes

Looking for specific function call

Searching

  • searched for Call to undefined function from http://jpauli.github.io/2015/01/22/on-php-function-calls.html

  • found zend_vm_execute.c file

  • just scanning the file and found execute_ex which appears to be loop

  • put some printf command there

  • Run /Users/anjesh/Dev/source/php-5.6.30/sapi/cli/php test.php and got that printf msg

  • Read README.ZEND_VM file and it talks about zend_vm_def.h, which is mentioned in zend_vm_gen.php and that file has some comments that it generates files This script creates zend_vm_execute.h and zend_vm_opcodes.h from existing zend_vm_def.h and zend_vm_execute.skl

  • Run /Users/anjesh/Dev/source/php-5.6.30/sapi/cli/php Zend/zend_vm_gen.php and comment in zend_vm_def.h is reflected in zend_vm_execute.c

  • http://jpauli.github.io/2015/01/22/on-php-function-calls.html content is present in zend_vm_def.h

  • php under the hoods https://www.youtube.com/watch?v=tyEFF7brU-I

  • message is coming from zend_verify_arg_class_kind in zend_execute.c, when searched for instance of text of the error message.

  • found where the message is coming from in zend_execute.c

    else if (Z_TYPE_P(arg) != IS_NULL || !(cur_arg_info->allow_null || (default_value && is_null_constant(default_value TSRMLS_CC)))) {
			need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
			return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, zend_zval_type_name(arg), "" TSRMLS_CC);
		}
  • i can replace need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC); with class_name = " myclass "; need_msg = " hello "; and the output message is changed.
  • if i comment above line, the output appears, infact it doesn't check for the typehint in the function param
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment