3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Laravel; use Closure, ArrayAccess; class View implements ArrayAccess { /** * The name of the view. * * @var string */ public $view; /** * The view data. * * @var array */ public $data; /** * The path to the view on disk. * * @var string */ public $path; /** * All of the shared view data. * * @var array */ public static $shared = array(); /** * All of the registered view names. * * @var array */ public static $names = array(); /** * The cache content of loaded view files. * * @var array */ public static $cache = array(); /** * THe last view to be rendered. * * @var string */ public static $last; /** * The render operations taking place. * * @var int */ public static $render_count = 0; /** * The Laravel view loader event name. * * @var string */ const loader = 'laravel.view.loader'; /** * The Laravel view engine event name. * * @var string */ const engine = 'laravel.view.engine'; /** * Create a new view instance. * * <code> * // Create a new view instance * $view = new View('home.index'); * * // Create a new view instance of a bundle's view * $view = new View('admin::home.index'); * * // Create a new view instance with bound data * $view = new View('home.index', array('name' => 'Taylor')); * </code> * * @param string $view * @param array $data * @return void */ public function __construct($view, $data = array()) { $this->view = $view; $this->data = $data; // In order to allow developers to load views outside of the normal loading // conventions, we'll allow for a raw path to be given in place of the // typical view name, giving total freedom on view loading. if (starts_with($view, 'path: ')) { $this->path = substr($view, 6); } else { $this->path = $this->path($view); } // If a session driver has been specified, we will bind an instance of the // validation error message container to every view. If an error instance // exists in the session, we will use that instance. if ( ! isset($this->data['errors'])) { if (Session::started() and Session::has('errors')) { $this->data['errors'] = Session::get('errors'); } else { $this->data['errors'] = new Messages; } } } /** * Determine if the given view exists. * * @param string $view * @param boolean $return_path * @return string|bool */ public static function exists($view, $return_path = false) { if (starts_with($view, 'name: ') and array_key_exists($name = substr($view, 6), static::$names)) { $view = static::$names[$name]; } list($bundle, $view) = Bundle::parse($view); $view = str_replace('.', '/', $view); // We delegate the determination of view paths to the view loader event // so that the developer is free to override and manage the loading // of views in any way they see fit for their application. $path = Event::until(static::loader, array($bundle, $view)); if ( ! is_null($path)) { return $return_path ? $path : true; } return false; } /** * Get the path to a given view on disk. * * @param string $view * @return string */ protected function path($view) { if ($path = $this->exists($view,true)) { return $path; } throw new \Exception("View [$view] doesn't exist."); } /** * Get the path to a view using the default folder convention. * * @param string $bundle * @param string $view * @param string $directory * @return string */ public static function file($bundle, $view, $directory) { $directory = str_finish($directory, DS); // Views may have either the default PHP file extension or the "Blade" // extension, so we will need to check for both in the view path // and return the first one we find for the given view. if (file_exists($path = $directory.$view.EXT)) { return $path; } elseif (file_exists($path = $directory.$view.BLADE_EXT)) { return $path; } } /** * Create a new view instance. * * <code> * // Create a new view instance * $view = View::make('home.index'); * * // Create a new view instance of a bundle's view * $view = View::make('admin::home.index'); * * // Create a new view instance with bound data * $view = View::make('home.index', array('name' => 'Taylor')); * </code> * * @param string $view * @param array $data * @return View */ public static function make($view, $data = array()) { return new static($view, $data); } /** * Create a new view instance of a named view. * * <code> * // Create a new named view instance * $view = View::of('profile'); * * // Create a new named view instance with bound data * $view = View::of('profile', array('name' => 'Taylor')); * </code> * * @param string $name * @param array $data * @return View */ public static function of($name, $data = array()) { return new static(static::$names[$name], $data); } /** * Assign a name to a view. * * <code> * // Assign a name to a view * View::name('partials.profile', 'profile'); * * // Resolve an instance of a named view * $view = View::of('profile'); * </code> * * @param string $view * @param string $name * @return void */ public static function name($view, $name) { static::$names[$name] = $view; } /** * Register a view composer with the Event class. * * <code> * // Register a composer for the "home.index" view * View::composer('home.index', function($view) * { * $view['title'] = 'Home'; * }); * </code> * * @param string|array $views * @param Closure $composer * @return void */ public static function composer($views, $composer) { $views = (array) $views; foreach ($views as $view) { Event::listen("laravel.composing: {$view}", $composer); } } /** * Get the rendered contents of a partial from a loop. * * @param string $view * @param array $data * @param string $iterator * @param string $empty * @return string */ public static function render_each($view, array $data, $iterator, $empty = 'raw|') { $result = ''; // If is actually data in the array, we will loop through the data and // append an instance of the partial view to the final result HTML, // passing in the iterated value of the data array. if (is_array($data) and count($data) > 0) { foreach ($data as $key => $value) { $with = array('key' => $key, $iterator => $value); $result .= render($view, $with); } } // If there is no data in the array, we will render the contents of // the "empty" view. Alternatively, the "empty view" can be a raw // string that is prefixed with "raw|" for convenience. else { if (starts_with($empty, 'raw|')) { $result = substr($empty, 4); } else { $result = render($empty); } } return $result; } /** * Get the evaluated string content of the view. * * @return string */ public function render() { static::$render_count++; Event::fire("laravel.composing: {$this->view}", array($this)); $contents = null; // If there are listeners to the view engine event, we'll pass them // the view so they can render it according to their needs, which // allows easy attachment of other view parsers. if (Event::listeners(static::engine)) { $result = Event::until(static::engine, array($this)); if ( ! is_null($result)) $contents = $result; } if (is_null($contents)) $contents = $this->get(); static::$render_count--; if (static::$render_count == 0) { Section::$sections = array(); } return $contents; } /** * Get the evaluated contents of the view. * * @return string */ public function get() { $__data = $this->data(); // The contents of each view file is cached in an array for the // request since partial views may be rendered inside of for // loops which could incur performance penalties. ob_start(); extract($__data, EXTR_SKIP); include $this->path; // We'll include the view contents for parsing within a catcher // so we can avoid any WSOD errors. If an exception occurs we // will throw it out to the exception handler. $content = ob_get_clean(); unset($__data); // The view filter event gives us a last chance to modify the // evaluated contents of the view and return them. This lets // us do something like run the contents through Jade, etc. if (Event::listeners('view.filter')) { return Event::first('view.filter', array($content, $this->path)); } return $content; } /** * Get the contents of the view file from disk. * * @return string */ protected function load() { static::$last = array('name' => $this->view, 'path' => $this->path); if (isset(static::$cache[$this->path])) { return static::$cache[$this->path]; } else { $pathba = $this->path; include $pathba; #return static::$cache[$this->path] = $sta; } } /** * Get the array of view data for the view instance. * * The shared view data will be combined with the view data. * * @return array */ public function data() { $data = array_merge($this->data, static::$shared); // All nested views and responses are evaluated before the main view. // This allows the assets used by nested views to be added to the // asset container before the main view is evaluated. foreach ($data as $key => $value) { if ($value instanceof View or $value instanceof Response) { $data[$key] = $value->render(); } } return $data; } /** * Add a view instance to the view data. * * <code> * // Add a view instance to a view's data * $view = View::make('foo')->nest('footer', 'partials.footer'); * * // Equivalent functionality using the "with" method * $view = View::make('foo')->with('footer', View::make('partials.footer')); * </code> * * @param string $key * @param string $view * @param array $data * @return View */ public function nest($key, $view, $data = array()) { return $this->with($key, static::make($view, $data)); } /** * Add a key / value pair to the view data. * * Bound data will be available to the view as variables. * * @param string $key * @param mixed $value * @return View */ public function with($key, $value = null) { if (is_array($key)) { $this->data = array_merge($this->data, $key); } else { $this->data[$key] = $value; } return $this; } /** * Add a key / value pair to the shared view data. * * Shared view data is accessible to every view created by the application. * * @param string $key * @param mixed $value * @return View */ public function shares($key, $value) { static::share($key, $value); return $this; } /** * Add a key / value pair to the shared view data. * * Shared view data is accessible to every view created by the application. * * @param string $key * @param mixed $value * @return void */ public static function share($key, $value) { static::$shared[$key] = $value; } /** * Implementation of the ArrayAccess offsetExists method. */ public function offsetExists($offset) { return array_key_exists($offset, $this->data); } /** * Implementation of the ArrayAccess offsetGet method. */ public function offsetGet($offset) { if (isset($this[$offset])) return $this->data[$offset]; } /** * Implementation of the ArrayAccess offsetSet method. */ public function offsetSet($offset, $value) { $this->data[$offset] = $value; } /** * Implementation of the ArrayAccess offsetUnset method. */ public function offsetUnset($offset) { unset($this->data[$offset]); } /** * Magic Method for handling dynamic data access. */ public function __get($key) { return $this->data[$key]; } /** * Magic Method for handling the dynamic setting of data. */ public function __set($key, $value) { $this->data[$key] = $value; } /** * Magic Method for checking dynamically-set data. */ public function __isset($key) { return isset($this->data[$key]); } /** * Get the evaluated string content of the view. * * @return string */ public function __toString() { return $this->render(); } /** * Magic Method for handling dynamic functions. * * This method handles calls to dynamic with helpers. */ public function __call($method, $parameters) { if (strpos($method, 'with_') === 0) { $key = substr($method, 5); return $this->with($key, $parameters[0]); } throw new \Exception("Method [$method] is not defined on the View class."); } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.40.0070.00718.83
8.3.30.0110.01119.27
8.3.20.0060.01220.25
8.3.10.0000.00823.57
8.3.00.0080.00019.56
8.2.170.0090.00922.96
8.2.160.0000.01420.57
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0030.00519.23
8.2.110.0090.01519.21
8.2.100.0090.00617.72
8.2.90.0030.00617.63
8.2.80.0030.00617.97
8.2.70.0080.00018.05
8.2.60.0060.00318.09
8.2.50.0030.00518.10
8.2.40.0030.00519.51
8.2.30.0030.00619.38
8.2.20.0040.00417.65
8.2.10.0000.00817.98
8.2.00.0040.00417.80
8.1.270.0040.00423.92
8.1.260.0050.00326.35
8.1.250.0000.00928.09
8.1.240.0060.00322.34
8.1.230.0040.00722.20
8.1.220.0000.00917.78
8.1.210.0080.00018.77
8.1.200.0070.00317.25
8.1.190.0030.00517.35
8.1.180.0040.00418.10
8.1.170.0030.00518.77
8.1.160.0000.00819.00
8.1.150.0040.00419.04
8.1.140.0090.00017.46
8.1.130.0000.00717.81
8.1.120.0000.00717.41
8.1.110.0000.00917.39
8.1.100.0040.00417.59
8.1.90.0050.00317.58
8.1.80.0000.00817.52
8.1.70.0040.00417.40
8.1.60.0090.00017.52
8.1.50.0040.00417.54
8.1.40.0030.00617.48
8.1.30.0030.00617.68
8.1.20.0040.00417.68
8.1.10.0080.00017.38
8.1.00.0000.00917.42
8.0.300.0000.00818.77
8.0.290.0060.00316.63
8.0.280.0040.00418.38
8.0.270.0050.00317.35
8.0.260.0030.00317.25
8.0.250.0000.00716.93
8.0.240.0040.00416.92
8.0.230.0030.00417.05
8.0.220.0000.00716.99
8.0.210.0000.00716.93
8.0.200.0000.01116.93
8.0.190.0040.00417.01
8.0.180.0080.00016.91
8.0.170.0040.00416.98
8.0.160.0080.00017.01
8.0.150.0000.00716.91
8.0.140.0050.00316.96
8.0.130.0060.00013.37
8.0.120.0030.00516.87
8.0.110.0000.00716.94
8.0.100.0050.00316.86
8.0.90.0040.00417.00
8.0.80.0150.00616.98
8.0.70.0020.00516.94
8.0.60.0000.00716.79
8.0.50.0030.00616.77
8.0.30.0130.00617.23
8.0.20.0130.01117.40
8.0.10.0040.00416.90
8.0.00.0130.00516.87
7.4.330.0030.00315.00
7.4.320.0030.00316.51
7.4.300.0000.00816.69
7.4.290.0000.00716.66
7.4.280.0030.00516.56
7.4.270.0000.00816.59
7.4.260.0000.00716.63
7.4.250.0000.00716.63
7.4.240.0030.00416.59
7.4.230.0030.00316.75
7.4.220.0090.00916.64
7.4.210.0030.01216.68
7.4.200.0070.00016.45
7.4.160.0070.01016.48
7.4.150.0030.01417.40
7.4.140.0140.00717.86
7.4.130.0130.00316.52
7.4.120.0090.01016.45
7.4.110.0030.01416.50
7.4.100.0080.00816.63
7.4.90.0000.01716.43
7.4.80.0150.01019.39
7.4.70.0170.00316.37
7.4.60.0140.00416.54
7.4.50.0050.00016.52
7.4.40.0120.01216.33
7.4.30.0130.00316.46
7.4.00.0070.00914.99
7.3.330.0000.00513.02
7.3.320.0000.00513.29
7.3.310.0070.00016.10
7.3.300.0050.00216.29
7.3.290.0090.00616.24
7.3.280.0120.00816.29
7.3.270.0150.00317.40
7.3.260.0060.01916.26
7.3.250.0110.00616.30
7.3.240.0140.00316.57
7.3.230.0160.00316.39
7.3.210.0080.00916.38
7.3.200.0070.01019.39
7.3.190.0080.01216.30
7.3.180.0060.01316.20
7.3.170.0140.00716.56
7.3.160.0100.01416.37
7.3.120.0090.00914.68
7.3.110.0060.00914.95
7.3.100.0060.00914.79
7.3.90.0040.00714.77
7.3.80.0090.00415.00
7.3.70.0080.00514.58
7.3.60.0080.00514.90
7.3.50.0080.00714.81
7.3.40.0080.00814.90
7.3.30.0020.00914.89
7.3.20.0070.00616.64
7.3.10.0050.01016.59
7.3.00.0080.00616.57
7.2.330.0130.01016.49
7.2.320.0130.00716.66
7.2.310.0060.01616.41
7.2.300.0100.00716.39
7.2.290.0100.00716.80
7.2.250.0050.01215.21
7.2.240.0080.01215.04
7.2.230.0060.00815.03
7.2.220.0030.00814.90
7.2.210.0030.01214.76
7.2.200.0080.00614.79
7.2.190.0040.00914.88
7.2.180.0020.01014.81
7.2.170.0050.01214.71
7.2.60.0000.01316.73
7.2.00.0090.00319.34
7.1.330.0070.00815.74
7.1.320.0070.00515.80
7.1.310.0090.00715.60
7.1.300.0050.00615.63
7.1.290.0090.00515.41
7.1.280.0020.01015.73
7.1.270.0030.00815.69
7.1.260.0050.00915.61
7.1.200.0000.01315.18
7.1.100.0030.00817.83
7.1.70.0070.00316.93
7.1.60.0100.01319.70
7.1.50.0280.01334.71
7.1.00.0070.07322.35
7.0.200.0080.00416.72
7.0.140.0030.07322.11
7.0.100.0170.07020.09
7.0.90.0400.08320.02
7.0.80.0170.07019.94
7.0.70.0400.07720.06
7.0.60.0430.08019.96
7.0.50.0370.07720.40
7.0.40.0070.08720.04
7.0.30.0170.07020.03
7.0.20.0070.08019.95
7.0.10.0070.08020.06
7.0.00.0070.06020.14
5.6.280.0070.07321.20
5.6.250.0070.07720.81
5.6.240.0200.07020.71
5.6.230.0070.08720.54
5.6.220.0030.08020.70
5.6.210.0030.08720.68
5.6.200.0070.05021.05
5.6.190.0100.08021.14
5.6.180.0200.07321.07
5.6.170.0000.07721.09
5.6.160.0130.08721.14
5.6.150.0100.07721.06
5.6.140.0230.06721.20
5.6.130.0070.07721.16
5.6.120.0030.08720.96
5.6.110.0000.09321.18
5.6.100.0100.07721.12
5.6.90.0130.06721.12
5.6.80.0130.08020.39
5.6.70.0130.06720.44
5.6.60.0100.07020.57
5.6.50.0100.06720.44
5.6.40.0230.06720.57
5.6.30.0170.07020.40
5.6.20.0130.06320.46
5.6.10.0100.07720.41
5.6.00.0100.04720.39
5.5.380.0030.07320.45
5.5.370.0000.09320.45
5.5.360.0070.05320.38
5.5.350.0130.06320.48
5.5.340.0130.05320.88
5.5.330.0030.08020.96
5.5.320.0070.08320.97
5.5.310.0100.07720.93
5.5.300.0030.07020.77
5.5.290.0030.05020.81
5.5.280.0070.08020.66
5.5.270.0100.08020.87
5.5.260.0100.07720.83
5.5.250.0070.07720.68
5.5.240.0070.08020.34
5.5.230.0170.07020.30
5.5.220.0070.07320.27
5.5.210.0100.06720.24
5.5.200.0170.07720.13
5.5.190.0070.05320.18
5.5.180.0030.07320.28
5.5.160.0230.06020.12
5.5.150.0070.08020.21
5.5.140.0100.07320.30
5.5.130.0100.07320.25
5.5.120.0070.08020.22
5.5.110.0030.06020.25
5.5.100.0030.04720.05
5.5.90.0070.05020.00
5.5.80.0170.04320.17
5.5.70.0030.08320.18
5.5.60.0070.08020.09
5.5.50.0130.07020.16
5.5.40.0030.04020.18
5.5.30.0130.07020.00
5.5.20.0000.08720.05
5.5.10.0070.07719.97
5.5.00.0100.08019.99
5.4.450.0070.06019.30
5.4.440.0100.07719.38
5.4.430.0070.07019.37
5.4.420.0130.06319.55
5.4.410.0130.06319.33
5.4.400.0130.07018.90
5.4.390.0030.05319.24
5.4.380.0200.06318.91
5.4.370.0100.04319.09
5.4.360.0130.07318.90
5.4.350.0100.07018.97
5.4.340.0070.07718.91
5.4.320.0070.07019.06
5.4.310.0070.07319.09
5.4.300.0070.05019.16
5.4.290.0000.05018.91
5.4.280.0030.05319.06
5.4.270.0030.07719.19
5.4.260.0100.07318.86
5.4.250.0030.05019.05
5.4.240.0030.07318.86
5.4.230.0130.07319.22
5.4.220.0070.07318.87
5.4.210.0100.07018.89
5.4.200.0070.04319.22
5.4.190.0130.05019.15
5.4.180.0100.05019.08
5.4.170.0170.06719.22
5.4.160.0100.06318.88
5.4.150.0170.07019.20
5.4.140.0070.07316.43
5.4.130.0070.04316.52
5.4.120.0100.03716.45
5.4.110.0030.04716.45
5.4.100.0000.03716.53
5.4.90.0030.03316.57
5.4.80.0030.03716.52
5.4.70.0070.03016.41
5.4.60.0000.03716.31
5.4.50.0030.03716.52
5.4.40.0000.04016.47
5.4.30.0000.03316.45
5.4.20.0070.03016.41
5.4.10.0070.04716.48
5.4.00.0000.03715.81
5.3.290.0170.05714.86
5.3.280.0030.05314.79
5.3.270.0100.06314.83
5.3.260.0030.08014.63
5.3.250.0070.07314.63
5.3.240.0070.06714.81
5.3.230.0030.04714.73
5.3.220.0000.04014.69
5.3.210.0070.03714.61
5.3.200.0070.03714.73
5.3.190.0070.03714.62
5.3.180.0070.03714.72
5.3.170.0030.03714.64
5.3.160.0000.06314.61
5.3.150.0000.04314.59
5.3.140.0030.03714.73
5.3.130.0070.03714.68
5.3.120.0000.04014.63
5.3.110.0070.03714.57
5.3.100.0030.07314.20
5.3.90.0100.03314.14
5.3.80.0030.07314.24
5.3.70.0030.04714.09
5.3.60.0100.06014.21
5.3.50.0000.05314.17
5.3.40.0130.05014.08
5.3.30.0030.04314.07
5.3.20.0070.06013.86
5.3.10.0030.03313.89
5.3.00.0070.04713.80

preferences:
40.9 ms | 400 KiB | 5 Q