Use PHP functions in JavaScript

JavaScript stream_context_get_default

Get a handle on the default file/stream context and optionally set parameters

1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
25
function stream_context_get_default (options) {
    // Get a handle on the default file/stream context and optionally set parameters  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/stream_context_get_default    // +   original by: Brett Zamir (http://brett-zamir.me)
    // -    depends on: stream_context_create
    // %          note 1: Although for historical reasons in PHP, this function can be used with
    // %          note 1: its options argument to set the default, it is no doubt best to use
    // %          note 1: stream_context_set_default() to do so    // *     example 1: var context = stream_context_get_default();
    // *     example 1: get_resource_type(context);
    // *     returns 1: 'stream-context'
    // BEGIN REDUNDANT
    this.php_js = this.php_js || {};    // END REDUNDANT
    if (!this.php_js.default_streams_context) {
        this.php_js.default_streams_context = this.stream_context_create(options);
    }
    if (options) {        this.php_js.default_streams_context.stream_options = options;
    }
 
    return this.php_js.default_streams_context;
}
external links: original PHP docs | raw js source

Examples

Running

1
2
var context = stream_context_get_default();
get_resource_type(context);

Should return

1
'stream-context'

Dependencies

In order to use this function, you also need:

Open syntax issues

php.js uses JsLint to help us keep our code consistent and prevent some common bugs.

Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.


Authors

Thanks to the following developers, you get to have stream_context_get_default goodness in JavaScript.

Comments

Add Comment
Use:
[CODE]
your_stuff('here');
[/CODE]
for proper code formatting
By submitting code here you are allowing us to use it in php.js hence dual licensing it under the MIT and GPL licenses

No comments yet. Be the first!


Contribute a New function

More functions

In this category

stream_context_create
» stream_context_get_default
stream_context_get_options
stream_context_get_params
stream_context_set_default
stream_context_set_option
stream_context_set_params
stream_get_contents
stream_get_line
stream_is_local

Support us

spread the word:


Use any PHP function in JavaScript


These kind folks have already donated: AYHAN BARI*, Nikita Ekshiyan, Nikita Ekshiyan, Petr Pavel, @HalfWinter, Paulo Freitas, Andros Peña Romo, @andorosu, Raimund Szabo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
<your name here>

Click here to lend your support to: phpjs and make a donation at www.pledgie.com !