From 79701af5019f25af65a30f4a8b4bdd3022035566 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 12 Dec 2013 17:41:38 -0500 Subject: [PATCH] Make Hash::numeric() accept more numeric things. Negative numbers and other stringy forms of numbers should be accepted. The name Hash::numeric implies is_numeric which it now uses. Fixes #2478 --- lib/Cake/Test/Case/Utility/HashTest.php | 3 +++ lib/Cake/Utility/Hash.php | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 5df02e3ca..26bde007c 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -665,6 +665,9 @@ class HashTest extends CakeTestCase { $data = array('one', 2 => 'two', 3 => 'three', 4 => 'four', 'a' => 'five'); $this->assertFalse(Hash::numeric(array_keys($data))); + + $data = array(2.4, 1, 0, -1, -2); + $this->assertTrue(Hash::numeric($data)); } /** diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 630e82062..1cfe45d45 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -626,9 +626,7 @@ class Hash { if (empty($data)) { return false; } - $values = array_values($data); - $str = implode('', $values); - return (bool)ctype_digit($str); + return $data === array_filter($data, 'is_numeric'); } /**