Output out of order?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Margaret MacDonald

    Output out of order?

    Running on a single-cp machine under W2K, this test program

    <?php
    function show_array ( $s, $a )
    {
    echo '<table cellspacing="2" cellpadding="2 border="1" >
    <tr><td>======& nbsp;' . $s . '&nbsp;====== </td></tr>' ;
    if ( ! is_array($a) ) { echo '<br>not an array!<br>' ; return ; }
    foreach ( $a as $k => $v )
    {
    echo '<tr>' ;
    if ( is_array( $v ) ) show_array( $k, $v ) ;
    else echo '<td>' . $k . '</td><td>' . $v . '</td>' ;
    echo '</tr>' ;
    }

    $a = array( 3,4,5 ) ;
    $b = array( 30,40,50 ) ;

    $c = array( 'foo' => $a, 'bar' => $b ) ;
    $d = array( $a, $b ) ;

    show_array( 'c', $c ) ;
    show_array( 'd', $d ) ;
    flush() ;

    $x = array_splice( $c['foo'], 1, 1 ) ;
    $y = array_splice( $d[0], 1, 1 ) ;

    echo 'x is ' . $x[0] . ' and y is ' . $y[0] ;

    show_array( 'c', $c ) ;
    show_array( 'd', $d ) ;
    flush() ;

    }

    ....consistentl y shows the output from the 'x is ... y is' statement
    during the output of the *first* call to show_array('d') (specifically
    between $d[0] and $d[1]).

    I can't imagine what could be going on. This looks like there's an
    internal race condition of some kind, which I find very disturbing.
    I'm used to serial execution such that the total output of any
    subprogram will be queued to the CIO buffer before the output of
    statements that follow the subprogram call.

    Does anyone know what's going on here? I'm hoping it's something
    simple, obvious, and dumb that I'm just not seeing.

    TIA,
    Margaret
    --
    (To mail me, please change .not.invalid to .net, first.
    Apologies for the inconvenience.)
  • Janwillem Borleffs

    #2
    Re: Output out of order?

    Margaret MacDonald wrote:[color=blue]
    > Does anyone know what's going on here? I'm hoping it's something
    > simple, obvious, and dumb that I'm just not seeing.
    >[/color]

    One thing that's going on, is that you have placed the function calls inside
    the function, so it never gets executed.

    Besides that, the output is consistant with the input.


    JW



    Comment

    • Margaret MacDonald

      #3
      Re: Output out of order?

      Janwillem Borleffs wrote:
      [color=blue]
      >Margaret MacDonald wrote:[color=green]
      >> Does anyone know what's going on here? I'm hoping it's something
      >> simple, obvious, and dumb that I'm just not seeing.
      >>[/color]
      >
      >One thing that's going on, is that you have placed the function calls inside
      >the function, so it never gets executed.
      >
      >Besides that, the output is consistant with the input.[/color]

      oops, sorry, Janwillem, that's a typo...I missed out the closing curly
      bracket when I cut and pasted. The function closes immediately after
      the foreach loop.

      Margaret
      --
      (To mail me, please change .not.invalid to .net, first.
      Apologies for the inconvenience.)

      Comment

      Working...