Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

v2.0.0: The method Underscore\Types\Strings::length does not exist #71

Open
Antoine-Patel opened this issue Sep 17, 2015 · 0 comments
Open

Comments

@Antoine-Patel
Copy link

I was testing this library that looks really nice. I wanted to know how well it had multibyte support (UTF8 etc), and wrote some trivial code.

But I ran into a Uncaught exception 'BadMethodCallException' with message 'The method Underscore\Types\Strings::length does not exist' with version 2.0.0 (`"anahkiasen/underscore-php": "<=2.1.0" in composer.json).

I noticed with the CHANGELOG that the docs were still for version 1.x of underscore-php (String in the doc vs Strings), so I tried to use version 1.3.1, and this time it worked.

Here is the testing code I used for version 1.3.1 (it works without error):

<?php

use \Underscore\Types\String;

error_reporting( E_ALL );
ini_set( "display_errors", 1 );

require_once __DIR__ . '/vendor/autoload.php';

mb_internal_encoding("UTF-8");

?>

<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8>
    <title></title>
<body>

<?php
echo '<pre>';
// Standard library
echo strtoupper('fòôbàř'); 
echo PHP_EOL;

echo strlen('fòôbàř');           
echo PHP_EOL;

// mbstring
echo mb_strtoupper('fòôbàř');    
echo PHP_EOL;

echo mb_strlen('fòôbàř');       
echo PHP_EOL;

echo String::upper('fòôbàř');
echo PHP_EOL;

echo String::length('fòôbàř');
echo PHP_EOL;

echo '</pre>';

?>

</body>

The version 2.0.0 of the code is identical, except its Strings instead of String (At least that's what I'm assuming, if there is some documentation about updating 1.x code to 2.x code I missed it.):

<?php

use \Underscore\Types\Strings;

// [...] <- Same as before

echo Strings::upper('fòôbàř'); // Works fine.
echo PHP_EOL;

echo Strings::length('fòôbàř'); // Exception.
echo PHP_EOL;

echo '</pre>';

?>

</body>

The full error message is:

Fatal error:  Uncaught exception 'BadMethodCallException' with message 'The method Underscore\Types\Strings::length does not exist' in /home/___/stacks/lampstack-5.5.29-1/apache2/htdocs/underscore.php/vendor/anahkiasen/underscore-php/src/Traits/Repository.php:183
Stack trace:
#0 /home/___/stacks/lampstack-5.5.29-1/apache2/htdocs/underscore.php/index3.php(40): Underscore\Traits\Repository::__callStatic('length', Array)
#1 /home/___/stacks/lampstack-5.5.29-1/apache2/htdocs/underscore.php/index3.php(40): Underscore\Types\Strings::length('f\xC3\xB2\xC3\xB4b\xC3\xA0\xC5\x99')
#2 {main}
  thrown in /home/___/stacks/lampstack-5.5.29-1/apache2/htdocs/underscore.php/vendor/anahkiasen/underscore-php/src/Traits/Repository.php on line 183

Did the names of the methods change in version 2.x or something ? Because it's not mentioned in the CHANGELOG.


Environment (Bitnami LAMP Stack 5.5.29-1 (https://bitnami.com/stacks/)):

Bitnami LAMP stack ships with the following software versions:

   - Apache 2.4.16
   - MySQL 5.6.26
   - PHP 5.5.29
   - PHPMyAdmin 4.4.13.1
   - AWS SDK for PHP 1.6.2
   - Varnish 3.0.5
   - ImageMagick 6.7.5
   - SQLite 3.7.15.1
   - ModSecurity 2.6.7
   - Libraries for Couchbase 2.0.5
   - Couchbase PHP extension 1.1.5
   - Heroku client
   - Git 1.9.5
   - Ruby 2.2.3

It's not a huge issue for me; I'll use a version >=1.3.0 and <2.0.0 in the meantime.


By the way, you might want to showcase a bit that underscore-php's Strings handle correctly strings like 'fòôbàř', contrary to PHP's standard strlen and such. I was trying to decide between using underscore-php's Strings or Stringy, and the latter has a nice snippet about that here, but not underscore-php. I'm throwing it here just in case the Stringy's Readme (it could be elsewhere for underscore-php) is updated and the "Why?" section is removed:

// Standard library
strtoupper('fòôbàř');       // 'FòôBàř'
strlen('fòôbàř');           // 10

// mbstring
mb_strtoupper('fòôbàř');    // 'FÒÔBÀŘ'
mb_strlen('fòôbàř');        // '6'

// Stringy
s('fòôbàř')->toUpperCase(); // 'FÒÔBÀŘ'
s('fòôbàř')->length();      // '6'

But it's just a suggestion, you do what you want.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant