javascript - IIFE (Immediately Invoked Function Expression) in PHP? -
i wonder if php has equivalence of iife (immediately invoked function expression) of javascript. can php closure written anyhow can work javascript (invoking, dependency, injection, directive) ?
(function(){ mymodule = angular.module('myangularapplication', []); }());
this expression above known invoked function expression(iife). since function definition invoke whenever .js file loaded. main reason iife effective can have code executing without needing have global variables , functions. when this, our controller creation fail using global variable create controller module. circumvent problem lets use getter function angular.module associate controller module. , while @ it, why not put controller in iife too.
(function () { var bookscontroller = function ($scope) { $scope.message = "hello bookscontroller"; } angular.module('myangularapplication').controller('bookscontroller', bookscontroller); }());
source: http://www.codeproject.com/articles/995498/angular-tutorial-part-understanding-modules-and thank you.
in php 7, yes, can:
(function() { echo "yes, works in php 7.\n"; })();
this not work in php 5.x. instead, closest can come is:
call_user_func(function() { echo "this works too\n"; });
Comments
Post a Comment