Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Remove Stripe_Util::cloneArray() #7

Merged
merged 1 commit into from

2 participants

@epriestley

Summary: PHP has copy-on-write value-semantics for arrays. This method doesn't do anything. It would break references and convert Iterators to raw arrays, but isn't used to do either.

My editor also stripped some trailing whitespace.

I tried to figure out what problem this was solving when it was introduced, but blame goes past the first commit.

Test Plan: Ran unit tests. Many of them fail -- they seem to depend on a specific API key? Is there a way I can get them to work? But, these failures were the same before this change. Added a troll test to demonstrate that PHP has the behavior I claim it does. Grepped for 'arrayClone()'.

@epriestley epriestley Remove Stripe_Util::cloneArray()
Summary: PHP has copy-on-write value-semantics for arrays. This method doesn't do anything. It __would__ break references and convert Iterators to raw arrays, but isn't used to do either.

My editor also stripped some trailing whitespace.

I tried to figure out what problem this was solving when it was introduced, but blame goes past the first commit.

Test Plan: Ran unit tests. Many of them fail -- they seem to depend on a specific API key? Is there a way I can get them to work? But, these failures were the same before this change. Added a troll test to demonstrate that PHP has the behavior I claim it does. Grepped for 'arrayClone()'.
5d0d921
@pc pc merged commit 205b48a into stripe:master
@pc
Owner
pc commented

Good catch. Thanks.

@pc
Owner
pc commented

(This is now live as 1.6.3 at https://stripe.com/docs/libraries.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2012
  1. @epriestley

    Remove Stripe_Util::cloneArray()

    epriestley authored
    Summary: PHP has copy-on-write value-semantics for arrays. This method doesn't do anything. It __would__ break references and convert Iterators to raw arrays, but isn't used to do either.
    
    My editor also stripped some trailing whitespace.
    
    I tried to figure out what problem this was solving when it was introduced, but blame goes past the first commit.
    
    Test Plan: Ran unit tests. Many of them fail -- they seem to depend on a specific API key? Is there a way I can get them to work? But, these failures were the same before this change. Added a troll test to demonstrate that PHP has the behavior I claim it does. Grepped for 'arrayClone()'.
This page is out of date. Refresh to see the latest.
View
1  lib/Stripe/ApiRequestor.php
@@ -87,7 +87,6 @@ private function _requestRaw($meth, $url, $params)
throw new Stripe_AuthenticationError('No API key provided. (HINT: set your API key using "Stripe::setApiKey(<API-KEY>)". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email support@stripe.com if you have any questions.');
$absUrl = $this->apiUrl($url);
- $params = Stripe_Util::arrayClone($params);
$params = self::_encodeObjects($params);
$langVersion = phpversion();
$uname = php_uname();
View
12 lib/Stripe/Util.php
@@ -2,13 +2,6 @@
abstract class Stripe_Util
{
- public static function arrayClone($array)
- {
- if (!is_array($array))
- throw new Stripe_Error("Trying to clone non-array: $array");
- return array_merge($array);
- }
-
public static function isList($array)
{
if (!is_array($array))
@@ -27,9 +20,9 @@ public static function convertStripeObjectToArray($values)
foreach ($values as $k => $v) {
// FIXME: this is an encapsulation violation
if (Stripe_Object::$_permanentAttributes->includes($k)) {
- continue;
+ continue;
}
- if ($v instanceof Stripe_Object) {
+ if ($v instanceof Stripe_Object) {
$results[$k] = $v->__toArray(true);
}
else if (is_array($v)) {
@@ -54,7 +47,6 @@ public static function convertToStripeObject($resp, $apiKey)
array_push($mapped, self::convertToStripeObject($i, $apiKey));
return $mapped;
} else if (is_array($resp)) {
- $resp = self::arrayClone($resp);
if (isset($resp['object']) && is_string($resp['object']) && isset($types[$resp['object']]))
$class = $types[$resp['object']];
else
View
13 test/Stripe/UtilTest.php
@@ -11,13 +11,12 @@ public function testIsList()
$this->assertFalse(Stripe_Util::isList($notlist));
}
- public function testArrayClone()
+ public function testThatPHPHasValueSemanticsForArrays()
{
- try {
- Stripe_Util::arrayClone(1);
- $this->assertFalse(true);
- } catch (Stripe_Error $e) {
- $this->assertTrue(true);
- }
+ $original = array('php-arrays' => 'value-semantics');
+ $derived = $original;
+ $derived['php-arrays'] = 'reference-semantics';
+
+ $this->assertEqual('value-semantics', $original['php-arrays']);
}
}
Something went wrong with that request. Please try again.