Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 04-08-2008
xorax xorax is offline
Registered User
 
Name: Ivan Brykov
Organization: United Markets Information Syndicat
Project: Trading Platform Web Integration
 
Join Date: Oct 2007
Posts: 6
Unhappy Strange error in PHP

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:

Code:
int apiTradesCalcProfit(string group, TradeRecord TrIn, out TradeRecord TrOut) throws ServerError;
I'm trying to call it from PHP like this:
PHP Code:
$initial->apiTradesCalcProfit($group$t$res); 
and it throws at me :
Code:
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:
Code:
res = initial.apiTradesCalcProfit(group, t)
What could cause this error?
Reply With Quote
  #2 (permalink)  
Old 04-08-2008
mes's Avatar
mes mes is online now
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Hi,

As described in the manual, "out" parameters must be passed by reference in PHP. Using your example, the final parameter should be changed as follows:
Code:
$initial->apiTradesCalcProfit($group, $t, &$res);
Can you make this change to your program and try it again?

Cheers,
Mark
Reply With Quote
  #3 (permalink)  
Old 04-08-2008
xorax xorax is offline
Registered User
 
Name: Ivan Brykov
Organization: United Markets Information Syndicat
Project: Trading Platform Web Integration
 
Join Date: Oct 2007
Posts: 6
Quote:
Originally Posted by mes View Post
Can you make this change to your program and try it again?
Surely I tried to put ampersand in front of $res. With no success: PHP throws the same Fatal Error..
Reply With Quote
  #4 (permalink)  
Old 04-08-2008
mes's Avatar
mes mes is online now
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Quote:
Originally Posted by xorax View Post
Surely I tried to put ampersand in front of $res. With no success: PHP throws the same Fatal Error..
If you can post a complete example that demonstrates the problem, we will take a look at it.

Thanks,
Mark
Reply With Quote
  #5 (permalink)  
Old 04-08-2008
xorax xorax is offline
Registered User
 
Name: Ivan Brykov
Organization: United Markets Information Syndicat
Project: Trading Platform Web Integration
 
Join Date: Oct 2007
Posts: 6
Quote:
Originally Posted by mes View Post
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 Code:
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 :( 
And here is some part of my .ice file:
Code:
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):
Code:
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
Reply With Quote
  #6 (permalink)  
Old 04-08-2008
mes's Avatar
mes mes is online now
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
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,
Mark
Reply With Quote
  #7 (permalink)  
Old 04-09-2008
xorax xorax is offline
Registered User
 
Name: Ivan Brykov
Organization: United Markets Information Syndicat
Project: Trading Platform Web Integration
 
Join Date: Oct 2007
Posts: 6
Talking

Quote:
Originally Posted by mes View Post
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
Reply With Quote
  #8 (permalink)  
Old 04-09-2008
mes's Avatar
mes mes is online now
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
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,
Mark
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange SEGV ... joel vennin Help Center 3 08-02-2006 05:10 AM
Ice 2.1.2 and PHP SSL error ??? surfer Help Center 4 01-09-2006 06:29 AM
Strange compilation error with VC6 / Ice 1.4.0 annekat Help Center 3 07-05-2004 02:15 PM
Ice php error report fengxb Help Center 2 05-11-2004 07:06 AM
Ice Php 1.0.2 link error fengxb Help Center 12 03-09-2004 01:08 AM


All times are GMT -4. The time now is 08:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.