Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit bbcae90

Browse files
committed
Merge pull request #556 from SammyK/app-ids-as-string
Add better error checking for app IDs as int when greater than PHP_INT_MAX
2 parents ea65829 + 6cfb1db commit bbcae90

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Facebook/FacebookApp.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace Facebook;
2525

2626
use Facebook\Authentication\AccessToken;
27+
use Facebook\Exceptions\FacebookSDKException;
2728

2829
class FacebookApp implements \Serializable
2930
{
@@ -40,10 +41,18 @@ class FacebookApp implements \Serializable
4041
/**
4142
* @param string $id
4243
* @param string $secret
44+
*
45+
* @throws FacebookSDKException
4346
*/
4447
public function __construct($id, $secret)
4548
{
46-
$this->id = $id;
49+
if (!is_string($id)
50+
// Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false
51+
&& !is_int($id)) {
52+
throw new FacebookSDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.');
53+
}
54+
// We cast as a string in case a valid int was set on a 64-bit system and this is unserialised on a 32-bit system
55+
$this->id = (string) $id;
4756
$this->secret = $secret;
4857
}
4958

tests/FacebookAppTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,19 @@ public function testSerialization()
6363
$this->assertEquals('id', $newApp->getId());
6464
$this->assertEquals('secret', $newApp->getSecret());
6565
}
66+
67+
/**
68+
* @expectedException \Facebook\Exceptions\FacebookSDKException
69+
*/
70+
public function testOverflowIntegersWillThrow()
71+
{
72+
new FacebookApp(PHP_INT_MAX + 1, "foo");
73+
}
74+
75+
public function testUnserializedIdsWillBeString()
76+
{
77+
$newApp = unserialize(serialize(new FacebookApp(1, "foo")));
78+
79+
$this->assertSame('1', $newApp->getId());
80+
}
6681
}

0 commit comments

Comments
 (0)