Voting

: min(eight, five)?
(Example: nine)

The Note You're Voting On

Joseph Reilly
10 years ago
One note on the very useful example by "jon at sitewizard dot ca".
The following statements:
Statement 1:
$phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];
Statement 2:
$phpinfo[end(array_keys($phpinfo))][] = $match[2];

These two lines will produce the error "Strict Standards: Only variables should be passed by reference in...". The root of the error is in the incorrect use of the end() function. The code works but thows the said error.
To address this try using the following statements:

Statement 1 revision:
$keys = array_keys($phpinfo);
$phpinfo[end($keys)][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];

Statement 2 revision:
$keys = array_keys($phpinfo);
$phpinfo[end($keys)][] = $match[2];

This fixes the error.
To wrap it all in an example:
<?php
function quick_dev_insights_phpinfo() {
ob_start();
phpinfo(11);
$phpinfo = array('phpinfo' => array());

if(
preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=".*?")?><t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>)?)?</tr>)#s', ob_get_clean(), $matches, PREG_SET_ORDER)){
foreach(
$matches as $match){
if(
strlen($match[1])){
$phpinfo[$match[1]] = array();
}elseif(isset(
$match[3])){
$keys1 = array_keys($phpinfo);
$phpinfo[end($keys1)][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];
}else{
$keys1 = array_keys($phpinfo);
$phpinfo[end($keys1)][] = $match[2];

}

}
}

if(! empty(
$phpinfo)){
foreach(
$phpinfo as $name => $section) {
echo
"<h3>$name</h3>\n<table class='wp-list-table widefat fixed pages'>\n";
foreach(
$section as $key => $val){
if(
is_array($val)){
echo
"<tr><td>$key</td><td>$val[0]</td><td>$val[1]</td></tr>\n";
}elseif(
is_string($key)){
echo
"<tr><td>$key</td><td>$val</td></tr>\n";
}else{
echo
"<tr><td>$val</td></tr>\n";
}
}
}
echo
"</table>\n";
}else{
echo
"<h3>Sorry, the phpinfo() function is not accessable. Perhaps, it is disabled<a href='http://php.net/manual/en/function.phpinfo.php'>See the documentation.</a></h3>";
}
}
?>
Frankly, I went thought the trouble of adding this note because the example by "jon at sitewizard dot ca" is probably the best on the web, and thought it unfortunate that it throws errors. Hope this is useful to someone.

<< Back to user notes page

To Top