Results 1 to 2 of 2

Thread: php ice interface struct initialization

  1. #1
    dthompson is offline Registered User
    Name: Don Thompson
    Organization: Digital Federal Credit Union
    Project: credit card fraud monitoring
    Join Date
    Aug 2005
    Location
    south shore mass
    Posts
    10

    php ice interface struct initialization

    Hi,
    Is there a way to add a constructor to initialize a struct instance. I need to pass this as a parameter as shown in the code fragment.

    thanks,
    Don

    // section from CU.ice:
    module CU
    {
    // Transaction, becomes CU_Transaction
    struct Transaction {
    string posteff;
    int account;
    ...
    }
    bool transfer(Transaction from, Transaction to) throws PostError;
    }

    // testing usage of transfer from PHP
    $xferfrom = array ("posteff" => "2006-05-15","account" => (int)12345, "suffix" => (int)51, "accttype" => "S","mnemonic" => "SDT", "amount" => (double)12345.67);

    $fromshr = new CU_Transaction($xferfrom);
    // constructor doesn't work, so initialize the hard way
    $fromshr->posteff = '2006-05-16';
    $fromshr->account = 2;
    $fromshr->accttype = 83;
    $fromshr->suffix = 1;
    $fromshr->mnemonic = 'SWX';
    $fromshr->amount = 100;
    $fromshr->descr = 'xfer test from php';
    // now post the transfer
    $ok = $gcu->transfer($fromshr, $toshr);
    // it works!, PHP and Ice are Great!
    Don Thompson
    Digital Federal Credit Union
    www.dcu.org
    Ice Project: credit union core processing prototype which may expand to open source project.
    Current Environment:
    Debian Linux Sarge,
    mysql 4.1.11-Debian,
    mysql++ v 2.1.0.beta1,
    qt3 v 3.3.4,
    Ice-3.0.1
    IcePHP-3.0.1
    Server: c++ using mysql++ to access mysql db, with Ice interfaces.
    Desktop Client: c++ using qt3, Ice interfaces to Server
    Home Banking Client: Python using IcePy interface to Server
    Currently using PHP Client

  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 Don,

    The Slice-to-PHP mapping doesn't currently define a "one shot" constructor that accepts values for all data members. We probably should, but I don't think it would do what you want. It looks like what you want is a constructor that accepts an array containing values for each of the data members. This is something you could do yourself fairly easily:
    Code:
    $fromshr = new CU_Transaction;
    foreach($xferfrom as $key => $value)
        $fromshr->$key = $value;
    Hope that helps,
    - Mark

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Ice Manual Wrong About Properties Initialization
    By shebli in forum Help Center
    Replies: 3
    Last Post: 12-07-2010, 02:28 PM
  2. PHP + Overriding Interface
    By 7H3LaughingMan in forum Help Center
    Replies: 1
    Last Post: 09-08-2009, 06:44 PM
  3. Replies: 1
    Last Post: 02-05-2007, 08:59 AM
  4. PHP Returned Result into slice struct
    By dthompson in forum Help Center
    Replies: 1
    Last Post: 05-05-2006, 04:05 PM
  5. ICE and COM initialization question
    By gasproni in forum Help Center
    Replies: 1
    Last Post: 11-11-2005, 06:43 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
  •