Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Facebook/FacebookApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace Facebook;

use Facebook\Authentication\AccessToken;
use Facebook\Exceptions\FacebookSDKException;

class FacebookApp implements \Serializable
{
Expand All @@ -40,10 +41,18 @@ class FacebookApp implements \Serializable
/**
* @param string $id
* @param string $secret
*
* @throws FacebookSDKException
*/
public function __construct($id, $secret)
{
$this->id = $id;
if (!is_string($id)
// Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false
&& !is_int($id)) {
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.');
}
// 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
$this->id = (string) $id;
$this->secret = $secret;
}

Expand Down
15 changes: 15 additions & 0 deletions tests/FacebookAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,19 @@ public function testSerialization()
$this->assertEquals('id', $newApp->getId());
$this->assertEquals('secret', $newApp->getSecret());
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testOverflowIntegersWillThrow()
{
new FacebookApp(PHP_INT_MAX + 1, "foo");
}

public function testUnserializedIdsWillBeString()
{
$newApp = unserialize(serialize(new FacebookApp(1, "foo")));

$this->assertSame('1', $newApp->getId());
}
}