Google\Cloud\Storage\StorageObject::exists PHP Method

exists() public method

Example: if ($object->exists()) { echo "Object exists!"; }
public exists ( ) : boolean
return boolean
    public function exists()
    {
        try {
            $this->connection->getObject($this->identity + ['fields' => 'name']);
        } catch (NotFoundException $ex) {
            return false;
        }
        return true;
    }

Usage Example

 public function testDoesExistFalse()
 {
     $this->connection->getObject(Argument::any())->willThrow(new NotFoundException(null));
     $object = new StorageObject($this->connection->reveal(), 'object.txt', 'bucket');
     $this->assertFalse($object->exists());
 }