No, I don’t think it is – that looks like it’s actually an error in the code. Just one that comes up very rarely, since it’s uncommon not to have the multibyte string extensions for PHP installed. I’ll look at it, although the fallback functions for multibyte string functions are a relatively low priority for me.
I have mbstring compiled in (PHP version 7.0 from GIT):
mbstring
Multibyte Support enabled
Multibyte string engine libmbfl
HTTP input encoding translation disabled
libmbfl version 1.3.2
oniguruma version 5.9.6
mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.
Multibyte (japanese) regex support enabled
Multibyte regex (oniguruma) backtrack check On
Multibyte regex (oniguruma) version 5.9.6
Directive Local Value Master Value
mbstring.detect_order no value
mbstring.encoding_translation Off
mbstring.func_overload 0
mbstring.http_input no value
mbstring.http_output no value
mbstring.http_output_conv_mimetypes ^(text/|application/xhtml\+xml)
mbstring.internal_encoding no value
mbstring.language neutral
mbstring.strict_detection Off
mbstring.substitute_character no value
That’s odd, then. Unless PHP 7 is removing the mb_substr function; but I haven’t heard anything about that, and I’d expect that kind of breaking change to be pretty widely publicized, so it’s pretty unlikely.
If your server is running with multibyte support, then it shouldn’t be running that function, so I’m not sure why you’d get that error. But then PHP 7 is still in beta, so it could be something random.
In reviewing, this is *definitely* a bug in the fallback function, by the way. I don’t know why your installation is running the function in the first place, but it is a bug.
I’m also getting this error while using PHP 7.0.3.
PHP Fatal error: Cannot use "self" when no class scope is active in wp-content/plugins/wp-to-twitter/wpt-functions.php on line 122
I have tested this on several websites but I am always getting an error. Can you please fix it?
Yeah, you’re missing an entire function in your fallback logic. You haven’t defined mb_substr_split_uncode anywhere in your code.
FWIW, you probably copied a portion of your stuff (or at least, they are doing the same things as you) from here:
https://doc.wikimedia.org/mediawiki-core/master/php/Fallback_8php_source.html.
It looks like PHP 7 does not fail gracefully when using self outside of the context of a class, which shouldn’t be done anyways, and is probably a result of copy/pasta of this code from somewhere else, where it WAS included as part of a class.
I’m making this change to my code locally, but you might want to include this diff in your next release of WPT:
@@ -293,14 +293,59 @@ if ( ! function_exists( 'mb_strlen' ) ) {
}
if ( ! function_exists( 'mb_substr' ) ) {
+ function mb_substr_split_unicode( $str, $splitPos ) {
+ if ( $splitPos == 0 ) {
+ return 0;
+ }
+
+ $byteLen = strlen( $str );
+
+ if ( $splitPos > 0 ) {
+ if ( $splitPos > 256 ) {
+ // Optimize large string offsets by skipping ahead N bytes.
+ // This will cut out most of our slow time on Latin-based text,
+ // and 1/2 to 1/3 on East European and Asian scripts.
+ $bytePos = $splitPos;
+ while ( $bytePos < $byteLen && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
+ ++$bytePos;
+ }
+ $charPos = mb_strlen( substr( $str, 0, $bytePos ) );
+ } else {
+ $charPos = 0;
+ $bytePos = 0;
+ }
+
+ while ( $charPos++ < $splitPos ) {
+ ++$bytePos;
+ // Move past any tail bytes
+ while ( $bytePos < $byteLen && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
+ ++$bytePos;
+ }
+ }
+ } else {
+ $splitPosX = $splitPos + 1;
+ $charPos = 0; // relative to end of string; we don't care about the actual char position here
+ $bytePos = $byteLen;
+ while ( $bytePos > 0 && $charPos-- >= $splitPosX ) {
+ --$bytePos;
+ // Move past any tail bytes
+ while ( $bytePos > 0 && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
+ --$bytePos;
+ }
+ }
+ }
+
+ return $bytePos;
+ }
+
function mb_substr( $str, $start, $count = 'end' ) {
if ( $start != 0 ) {
- $split = self::mb_substr_split_unicode( $str, intval( $start ) );
+ $split = mb_substr_split_unicode( $str, intval( $start ) );
$str = substr( $str, $split );
}
if ( $count !== 'end' ) {
- $split = self::mb_substr_split_unicode( $str, intval( $count ) );
+ $split = mb_substr_split_unicode( $str, intval( $count ) );
$str = substr( $str, 0, $split );
}
Ah, nevermind. I was looking at an old version of the plugin. Looks like you fixed this in a recent release.
Oh, good. I was starting to wonder whether I was crazy… π