Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Only First Byte

When assigning a string to a position inside another string, PHP reports a warning: indeed, only the first byte is used.

PHP code

<?php

$str = 'xy';  

// first letter is now a
$str[0] = 'a';

// second letter is now b, c is ignored
$str[1] = 'bc';

echo $str;

?>

Before

ab

After

PHP Warning:  Only the first byte will be assigned to the string offset 

Warning: Only the first byte will be assigned to the string offset 
ab

PHP version change

This behavior changed in 8.0.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat