Skip to content

Instantly share code, notes, and snippets.

@ralphsaunders
Created June 12, 2012 21:31
Show Gist options
  • Save ralphsaunders/2920260 to your computer and use it in GitHub Desktop.
Save ralphsaunders/2920260 to your computer and use it in GitHub Desktop.
PHP preg_grep() throws a notice when passed array
/**
* This is my array, let's call him larry
*
* array(1) {
* ["canvas-snake"]=>
* array(5) {
* ["name"]=>
* string(12) "canvas-snake"
* ["server_path"]=>
* string(48) "/Applications/MAMP/htdocs/pl/posted/canvas-snake"
* ["size"]=>
* int(374)
* ["date"]=>
* int(1339533162)
* ["relative_path"]=>
* string(9) "./posted/"
* }
* }
*
*
* A PHP Error was encountered
*
* Severity: Notice
*
* Message: Array to string conversion
*
* Filename: models/posts_model.php
*
* Line Number: 70
*/
/**
* pretty urls
*/
$ugly_dirs = preg_grep( '/[A-Z]\S/', $larry );
if( ! empty( $ugly_dirs ) )
{
/**
* Note: the code in here *does* run and does work, it's just preg_grep
* doesn't like larry... poor larry
*/
foreach( $ugly_dirs as $dir )
{
rename( $root . $dir['name'], $root . $this->_format_url( $dir['name'] ) );
}
}
@iandunn
Copy link

iandunn commented Mar 24, 2014

Did you ever figure out why this is happening? It sounds like a PHP bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment