Results 1 to 3 of 3

Thread: Error creating structure

  1. #1
    Andrew Midson is offline Registered User
    Name: Andrew Midson
    Organization: Optimus Group Limited
    Project: Web gateway to print management information system
    Join Date
    Nov 2009
    Posts
    2

    Error creating structure

    I am trying to create an instance of the following structure using PHP:

    struct priceRequestInfo {
    int productId;
    string customer;
    opt4ice::decimal quantity;
    };

    where opt4ice::decimal has the following definition:

    struct decimal {
    long intval;
    short ndp;
    };

    The following code fails:

    $id = 1;
    $customer = "ABC";
    $quantity = new opt4ice_decimal(100, 2);
    $request = new priceRequestInfo($id, $customer, $quantity);

    The error message for the above is "Object of class opt4ice_decimal could not be converted to int".

    However the code below succeeds:

    $id = 1;
    $customer = "ABC";
    $quantity = new opt4ice_decimal(100, 2);
    $request = new priceRequestInfo($id, $customer, 0);
    $request->quantity = $quantity;

    If I just leave the last argument out (i.e. $request = new priceRequestInfo($id, $customer) ) then the structure is created correctly and the quantity attribute is a valid opt4ice::decimal. Is there a known problem passing a structure to the constructor of another structure or is this something new? Or am I just doing something wrong?

  2. #2
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    Hi Andrew,

    Welcome to the forum!

    You didn't describe your environment (Ice version, operating system, PHP version, etc.), so I tried to reproduce this issue with Ice 3.3.1 on CentOS using the default PHP version (5.1.6). Everything works correctly with this combination.

    However, I can see where the problem might lie. Add a call to Ice_dumpProfile to your PHP script:
    Code:
    <?php
    Ice_loadProfile();
    Ice_dumpProfile();
    ...
    This will cause the Ice extension to display all of the PHP code it generates from your Slice definitions. In the output you'll see the following:
    Code:
    class opt4ice_priceRequestInfo
    {
    function __construct($productId=0, $customer='', $quantity=-1)
    {
        $this->productId = $productId;
        $this->customer = $customer;
        $this->quantity = $quantity == -1 ? new opt4ice_decimal() : $quantity;
    }
    The generated code is using the value -1 as a marker to determine whether the caller supplied a value for the argument. Apparently, the version of PHP you are using does not allow such a comparison.

    We'll fix this bug in the next Ice release. Meanwhile, you can work around it as you suggested: by omitting the quantity argument and assigning the member after construction.

    Let us know if you have any further questions.

    Regards,
    Mark

  3. #3
    Andrew Midson is offline Registered User
    Name: Andrew Midson
    Organization: Optimus Group Limited
    Project: Web gateway to print management information system
    Join Date
    Nov 2009
    Posts
    2
    Mark

    Many thanks for your reply - that certainly makes sense given what I am seeing. I am running PHP 5.2.6 with Ice 3.3.0 on Ubuntu 9.0.4. It looks as though my version of PHP is trying to coerce $quantity to an integer to compare it to -1, which fails and generates the exception. Fortunately the work around is straightforward, but it's always nice to know what causes these things.

    Regards

    Andrew

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sequence inside a structure
    By msorensson in forum Help Center
    Replies: 1
    Last Post: 01-19-2009, 07:42 AM
  2. The structure and sequence of bytes
    By soff.dong in forum Help Center
    Replies: 1
    Last Post: 10-15-2008, 04:11 AM
  3. socket error creating endpoint on localhost
    By gminorcoles in forum Help Center
    Replies: 1
    Last Post: 08-11-2008, 05:16 PM
  4. member ambiguity error when creating a smart pointer
    By heathbar in forum Help Center
    Replies: 3
    Last Post: 04-09-2006, 05:32 PM
  5. application structure /design
    By leyang in forum Help Center
    Replies: 0
    Last Post: 12-27-2004, 08:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •