Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Standards and Best Practices Error Handling Exceptions

line 21 $statusGroup = $substr((string) $statusCode, 0, 1); what is (string)?

From the definition: string substr ( string $string, int $start [, int $length ] )

if $statusCode is string $string, 0 is int $start, and 1 is int $length, what's the purpose of (string) in that syntax from video, on line 21?

Thanks

2 Answers

Hi Paul,

The (string) part in this command typecasts $statusCode into a string type. You can see what I mean if you do a simple bit of PHP like this and compare the output of var_dump() on each of these sample variables:

<?php
$statusCode = 33524552452;
var_dump($statusCode);
$status = (string) $statusCode;
var_dump($status);
?>

Thanks for clarifying.

You're welcome, Paul! Happy Coding!