In PHP extension development, there is a method that needs to receive binary data. zend_parse_parameters sets the parameter type to "s". When the parameters are printed, they are empty. It seems that they are not received.
<code class="c">PHP_FUNCTION(hau_socket) { char *buf; int len; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &len) == FAILURE ) { return; } php_printf("str:%s, buf length:%d, len:\n", buf, strlen(buf), len); }</code>
<code><?php $packet = new SocketPacket();//使用pack函数打包进制数据 $packet->WriteBegin( 0x7070 ); $packet->WriteInt_N( 0x1001 ); $packet->WriteInt_N( 1 ); $packet->WriteInt_N(9055249); $packet->WriteEnd_n(); hau_socket( $packet->GetPacketBuffer() );</code>
<code>输出结果:str:, buf length:0, len: </code>
Is the parameter type setting incorrect? ?
In PHP extension development, there is a method that needs to receive binary data. zend_parse_parameters sets the parameter type to "s". When the parameters are printed, they are empty. It seems that they are not received.
<code class="c">PHP_FUNCTION(hau_socket) { char *buf; int len; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &len) == FAILURE ) { return; } php_printf("str:%s, buf length:%d, len:\n", buf, strlen(buf), len); }</code>
<code><?php $packet = new SocketPacket();//使用pack函数打包进制数据 $packet->WriteBegin( 0x7070 ); $packet->WriteInt_N( 0x1001 ); $packet->WriteInt_N( 1 ); $packet->WriteInt_N(9055249); $packet->WriteEnd_n(); hau_socket( $packet->GetPacketBuffer() );</code>
<code>输出结果:str:, buf length:0, len: </code>
Is the parameter type setting incorrect? ?
No problem was found in the use of zend_parse_parameters
, and you did not report a null pointer when printf
, indicating that buf
was indeed assigned. I think you should check if $packet->GetPacketBuffer()
returns a string.