Archived
This forum has been archived. Please start a new discussion on GitHub.
Strange error in PHP
in Help Center
Hello everybody!
I'm currently stuck with Fatal PHP error that I cannot explain. Perhaps you guys can help me.
So.. in my .ice file there is a record in interface:
I'm trying to call it from PHP like this:
[PHP]$initial->apiTradesCalcProfit($group, $t, $res);[/PHP]
and it throws at me :
At the same time it perfectly works in python:
What could cause this error?
I'm currently stuck with Fatal PHP error that I cannot explain. Perhaps you guys can help me.
So.. in my .ice file there is a record in interface:
int apiTradesCalcProfit(string group, TradeRecord TrIn, out TradeRecord TrOut) throws ServerError;
I'm trying to call it from PHP like this:
[PHP]$initial->apiTradesCalcProfit($group, $t, $res);[/PHP]
and it throws at me :
Fatal error: Ice_ObjectPrx::apitradescalcprofit() : expected int value but received null in ice_test.php on line 53
At the same time it perfectly works in python:
res = initial.apiTradesCalcProfit(group, t)
What could cause this error?
0
Comments
-
If you can post a complete example that demonstrates the problem, we will take a look at it.
No problem. I just thought it would be quite boring:) Here is the snippet of PHP code:
[PHP]
Ice_LoadProfile('my_server');
$base = $ICE->stringToProxy("MT:tcp -h ice.server.tld -p 10000");
$initial = $base->ice_checkedCast("::MTServer::Morda");
$symbol = 'EURUSD';
$group = 'Forex_USD';
$initial->apiSymbolsGet($symbol, &$sym_info); //works fine!
$initial->apiHistoryPrices($symbol, &$quote_bid, &$quote_ask, &$quote_time); //works fine either!
$t = new MTServer_TradeRecord();
$t->symbol = $symbol;
$t->volume = 100;
$t->OpenPrice = $quote_bid;
$t->ClosePrice = $quote_bid + $sym_info->point;
$res = new MTServer_TradeRecord();
$initial->apiTradesCalcProfit($group, $t, &$res); //Fatal Error here
[/PHP]
And here is some part of my .ice file:module MTServer { struct ConSymbol { ...a lot of stuff here.. }; struct TradeRecord { ...a lot of stuff here... }; interface Morda { //return: TRUE or exception int apiSymbolsGet(string symbol, out ConSymbol SymbolStruct) throws ServerError; //return: RET_OK or exception int apiHistoryPrices(string symbol, out double bid, out double ask, out int time) throws ServerError; int apiTradesCalcProfit(string group, TradeRecord TrIn, out TradeRecord TrOut) throws ServerError; }; };
And here is python code that works ok (just to compare):import Ice Ice.loadSlice('My.ice') import MTServer base = Ice.initialize().stringToProxy(MT:tcp -h ice.server.tld -p 10000') mtsrv = MTServer.MordaPrx.checkedCast(base) symbol = "EURUSD" sg = mtsrv.apiSymbolsGet(symbol) prices = mtsrv.apiHistoryPrices(symbol) t = MTServer.TradeRecord() t.symbol = symbol t.volume=100 t.OpenPrice = prices[1] t.ClosePrice = prices[1] + sg[1].point res = mtsrv.apiTradesCalcProfit("Forex_USD", t) print res #prints what expected
0 -
Hi,
I suspect the problem is caused by an uninitialized integer data member in your structure; PHP initializes the member to a null value by default, but the Ice extension expects an integer value. The Ice extension only accepts a null value for strings, objects and proxies; all other types must be initialized with a suitable default value.
We'll look at improving this situation in a future release.
Take care,
Mark0 -
I suspect the problem is caused by an uninitialized integer data member in your structure;
YES! It solved the problem! Thank you very much. Now after initialization of about 24 members of structure (there are ints and doubles too) it finally started working as expected. You saved my day:)0 -
Hi,
I'm glad to hear that you resolved the problem. Note that the final release of Ice 3.3.0 will add support for constructors in structures, exceptions and classes that initialize data members to legal default values.
Take care,
Mark0