Access to undeclared static property: CTextFilter::$code
Posted: Fri Dec 25, 2015 12:10 am
I can't seem to understand why this is happening...
I'm currently using PHP 7.0.0 (recently uppgraded from 5.6)
This is the Code:
CTextFilter.php
This is the Error:
Access to undeclared static property: CTextFilter::$code
I understand it as it wants the $code variable to be static but I can't figure out how to make it just that...
My tries:
Put it into the Class itself... (added public to it aswell and the result I got was: Code snippet 2:
Please do help me as I can't seem to understand where I went wrong or if this is a change from php 5.6 to 7.0.0
Thanks in advance,
Thomas
I'm currently using PHP 7.0.0 (recently uppgraded from 5.6)
This is the Code:
CTextFilter.php
Code: Select all
$text = "hello";
$filters = "markdown";
public function doFilter($text, $filters) {
// Define all valid filters with their callback function.
$code = array(
'bbcode' => 'bbcode2html',
'link' => 'make_clickable',
'markdown' => 'markdown',
'nl2br' => 'nl2br',
);
// Make an array of the comma separated string $filters
$filter = preg_replace('/\s/', '', explode(',', $filters));
// For each filter, call its function with the $text as parameter.
foreach($filter AS $func) {
var_dump($code[$func]);
if(isset($code[$func])) {
$text = self::$code[$func]($text);
}
else {
throw new Exception("The filter '$filters' is not a valid filter string.");
}
}
return $text;
}Access to undeclared static property: CTextFilter::$code
I understand it as it wants the $code variable to be static but I can't figure out how to make it just that...
My tries:
Code: Select all
static $code = array(
'bbcode' => 'bbcode2html',
'link' => 'make_clickable',
'markdown' => 'markdown',
'nl2br' => 'nl2br',
);Code: Select all
class CTextFilter {
/**
* Call each filter.
*
* @param string $text the text to filter.
* @param string $filters as comma separated list of filter.
* @return string the formatted text.
*/
// Define all valid filters with their callback function.
static $code = array(
'bbcode' => 'bbcode2html',
'link' => 'make_clickable',
'markdown' => 'markdown',
'nl2br' => 'nl2br',
);Code: Select all
The filter 'markdown' is not a valid filter string.Thanks in advance,
Thomas