public function write($string) {
        if (!$this->isWritable()) {
            throw new \RuntimeException('Stream is not writable');
        }
        if (!$this->eof()) {
            // copy the data after the cursor to another stream so that it can be written back
            $tempStream = $this->createStream();
            stream_copy_to_stream($this->stream, $tempStream);
            // reset cursors to their positions prior to the reading
            fseek($tempStream, 0);
            $this->seek($this->cursor);
        }
        $retval = fwrite($this->stream, $string);
        if ($retval === false) {
            throw new \RuntimeException('Write failed (fwrite returned false)');
        }
        $this->flen += $retval;
        $this->cursor += $retval;
        if (isset($tempStream)) {
            stream_copy_to_stream($tempStream, $this->stream);
            fclose($tempStream);
            $this->seek($this->cursor);
        }
        return $retval;
    }
public function write($string) {
        if (!$this->isWritable()) {
            throw new \RuntimeException('Stream is not writable');
        }
        if (!$this->eof()) {
            // copy the data after the cursor to another stream so that it can be written back
            $tempStream = $this->createStream();
            stream_copy_to_stream($this->stream, $tempStream);
            // reset cursors to their positions prior to the reading
            fseek($tempStream, 0);
            $this->seek($this->cursor);
        }
        $retval = fwrite($this->stream, $string);
        if ($retval === false) {
            throw new \RuntimeException('Write failed (fwrite returned false)');
        }
        $this->flen += $retval;
        $this->cursor += $retval;
        if (isset($tempStream)) {
            stream_copy_to_stream($tempStream, $this->stream);
            fclose($tempStream);
            $this->seek($this->cursor);
        }
        return $retval;
    }
public function write ( $ string ) { if ( ! $ this -> isWritable ( ) ) { throw new \ RuntimeException ( 'Stream is not writable' ) ; } if ( ! $ this -> eof ( ) ) { // copy the data after the cursor to another stream so that it can be written back $ tempStream = $ this -> createStream ( ) ; stream_copy_to_stream ( $ this -> stream , $ tempStream ) ; // reset cursors to their positions prior to the reading fseek ( $ tempStream , 0 ) ; $ this -> seek ( $ this -> cursor ) ; } $ retval = fwrite ( $ this -> stream , $ string ) ; if ( $ retval === false ) { throw new \ RuntimeException ( 'Write failed (fwrite returned false)' ) ; } $ this -> flen += $ retval ; $ this -> cursor += $ retval ; if ( isset ( $ tempStream ) ) { stream_copy_to_stream ( $ tempStream , $ this -> stream ) ; fclose ( $ tempStream ) ; $ this -> seek ( $ this -> cursor ) ; } return $ retval ; }
Write data to the stream via an insert.

This stream is meant to be used as an in-memory json object, overwriting a portion of the stream that has
already been written does not appear to have a meaningful use case.

@param string $string The string that is to be written.
@return int Returns the number of bytes written to the stream.
@throws \RuntimeException on failure.
Write data to the stream via an insert .