PHP code example of phptars / tars2php

1. Go to this page and download the library: Download phptars/tars2php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phptars / tars2php example snippets


    struct => \TARS_Struct
    sThe constructor of struct is special. It takes two parameters, classname and classfields

The first describes the name, and the second describes the information of the variables in struct



For example:
	class SimpleStruct extends \TARS_Struct {
		const ID = 0; //TARS file every struct的tag
		const COUNT = 1;

		public $id; //strcutThe values of each element in are saved here
		public $count; 

		protected static $fields = array(
			self::ID => array(
				'name'=>'id',//struct every element 
				'



namespace Server\servant\PHPTest\PHPServer\obj\classes;

class SimpleStruct extends \TARS_Struct {
	const ID = 0; //tars protocal tag
	const COUNT = 1;
	const PAGE = 2;
	
	public $id; //Actual value of element
	public $count; 
	public $page; 
	
	protected static $_fields = array(
		self::ID => array(
			'name'=>'id', //tars Name of no element in the agreement
			'


	try {
		$requestPacket = new RequestPacket(); //Parameters >_funcName = __FUNCTION__;
		$requestPacket->_servantName = $this->_servantName;
		
		$encodeBufs = [];

		$__buffer = TUPAPIWrapper::putStruct("tags",1,$tags,$this->_iVersion); //Package first parameter tags
		$encodeBufs['tags'] = $__buffer;
		
		$requestPacket->_encodeBufs = $encodeBufs; //Set request in request package bufs

		$sBuffer = $this->_communicator->invoke($requestPacket,$this->_iTimeout); //Send request package, receive return package

		$ret = TUPAPIWrapper::getStruct("outtags",2,$outtags,$sBuffer,$this->_iVersion); //Extract the first output parameter from the return packageouttags
		return TUPAPIWrapper::getInt32("",0,$sBuffer,$this->_iVersion); //The return parameter name is empty and the tag is 0

	}
	catch (\Exception $e) {
		throw $e;
	}