« MongoDB\BSON\Javascript
MongoDB\BSON\Javascript::getCode »

MongoDB\BSON\Javascript::__construct

(mongodb >=1.0.0)

MongoDB\BSON\Javascript::__construct — Construct a new Javascript

説明

final public function MongoDB\BSON\Javascript::__construct(string $code, array|object|null $scope = null)

パラメータ

code (string)

Javascript code.

scope (array|object)

Javascript scope.

エラー / 例外

変更履歴

バージョン 説明
PECL mongodb 1.2.0 MongoDB\Driver\Exception\InvalidArgumentException is thrown if code contains null bytes. Previously, values would be truncated at the first null byte.

例

例1 MongoDB\BSON\Javascript::__construct() example

<?php

$code = new MongoDB\BSON\Javascript('function() { return 1; }');
var_dump($code);

$codews = new MongoDB\BSON\Javascript('function() { return foo; }', ['foo' => 'bar']);
var_dump($codews);

?>

上の例の出力は以下となります。

object(MongoDB\BSON\Javascript)#1 (2) {
  ["javascript"]=>
  string(24) "function() { return 1; }"
  ["scope"]=>
  object(stdClass)#2 (0) {
  }
}
object(MongoDB\BSON\Javascript)#2 (2) {
  ["javascript"]=>
  string(26) "function() { return foo; }"
  ["scope"]=>
  object(stdClass)#1 (1) {
    ["foo"]=>
    string(3) "bar"
  }
}
関連キーワード:
Javascript   MongoDB   code   scope   construct   return   Construct   Driver   Exception   InvalidArgumentException   mongodb   Throws   contains   bytes   dump   codews   javascript   stdClass   getCode   final   argument   parsing   errors   履歴   thrown
関連する関数・ページ:
mongodb-bson-javascript.getcode   mongodb-bson-javascript.tostring   class.mongodb-bson-javascript   mongodb-bson-javascript.getscope   mongodb-bson-javascript.jsonserialize   mongodb-bson-int64.construct