Results 1 to 3 of 3

Thread: bug when pass a class by value

  1. #1
    damingyipai is offline Registered User
    Join Date
    Jan 2004
    Posts
    59

    Unhappy bug when pass a class by value

    slice:

    class item;

    sequence<item> items;
    class item
    {
    string title;
    items children;
    };

    ...
    item getitem();
    ...

    server side implement code:

    itemPtr getitem()
    {
    itemPtr i = new item;
    i->title = "root";

    itemPtr i2 = new item;
    i2->title = "sub1";
    i->children.push_back( i2 );

    itemPtr i3 = new item;
    i3->title = "sub2";
    i2->children.push_back( i3 );

    return i;
    }


    and PHP client side code:

    $nav = $obj->getitem();

    function dump_nav( $mynav, $level )
    {
    for ( $j = 0; $j != $level; ++ $j ) {
    echo " ";
    }
    echo $mynav->title;
    echo "<br/>";

    $child_count = count($mynav->children);
    for ( $i = 0; $i != $child_count; ++ $i ) {
    ftr_dump_nav( $mynav->children[ i ], level + 1 );
    }
    }

    dump_nav( $nav, 0 );

    PHP client result:

    "root
    "

    the well result is:

    "root
    sub1
    sub2"

    help me, please.

  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
    If you execute the following statement, you'll see that the object graph is being preserved correctly in PHP:
    Code:
    print_r($nav);
    There is a bug in your code which is preventing it from displaying the graph. The corrected line is shown below:
    Code:
    ftr_dump_nav( $mynav->children[ $i ], $level + 1 );
    Take care,
    - Mark

  3. #3
    damingyipai is offline Registered User
    Join Date
    Jan 2004
    Posts
    59

    I see, sorry for my harum-scarum

    :-)

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. how to pass a value array from c++ to php??
    By twister in forum Help Center
    Replies: 3
    Last Post: 11-10-2009, 07:49 AM
  2. Replies: 4
    Last Post: 10-16-2009, 06:51 PM
  3. Replies: 1
    Last Post: 11-29-2007, 07:26 AM
  4. Pass Object as payload
    By ashfaqframewala in forum Help Center
    Replies: 1
    Last Post: 07-24-2007, 07:32 AM
  5. Semantics of pass by value for interface
    By chaukmean in forum Help Center
    Replies: 2
    Last Post: 11-27-2003, 05:21 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
  •