note 116869 added to function.phpinfo
| From: | JosephReilly | Date: | Thu, 12 Mar 2015 22:44:17 +0000 |
| Subject: | note 116869 added to function.phpinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201931@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 72.52.91.14
Probable Submitter: 67.160.246.230
----
Manual Page -- http://php.net/manual/en/function.phpinfo.php
Edit -- https://master.php.net/note/edit/116869
Del: integrated -- https://master.php.net/note/delete/116869/integrated
Del: useless -- https://master.php.net/note/delete/116869/useless
Del: bad code -- https://master.php.net/note/delete/116869/bad+code
Del: spam -- https://master.php.net/note/delete/116869/spam
Del: non-english -- https://master.php.net/note/delete/116869/non-english
Del: in docs -- https://master.php.net/note/delete/116869/in+docs
Del: other reasons-- https://master.php.net/note/delete/116869
Reject -- https://master.php.net/note/reject/116869
Search -- https://master.php.net/manage/user-notes.php