php8.5
Home/ Manual/ bson / javascript/ MongoDB\BSON\Javascript::getScope

MongoDB\BSON\Javascript::getScope

PHP function Edit on GitHub ✎

(mongodb >=1.2.0)

Returns the Javascript's scope document

Description

MongoDB\BSON\Javascript::getScope(): object|null

Parameters Parameters

Return Values

Returns the Javascript's scope document, or null if the is no scope.

Errors/Exceptions

Examples

MongoDB\BSON\Javascript::getScope() example

php
<?php

$js = new MongoDB\BSON\Javascript('function foo(bar) { return bar; }');
var_dump($js->getScope());

$js = new MongoDB\BSON\Javascript('function foo() { return foo; }', ['foo' => 42]);
var_dump($js->getScope());

?>

The above example will output:

output
NULL
object(stdClass)#1 (1) {
  ["foo"]=>
  int(42)
}

See Also

  • BSON Types

Source: reference/mongodb/bson/javascript/getscope.xml · from the official PHP manual (php/doc-en)