php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74018 cannot assign anonymous function to static variable
Submitted: 2017-01-30 17:36 UTC Modified: 2017-01-30 17:42 UTC
From: zhuravlov dot ip at ya dot ru Assigned:
Status: Not a bug Package: Compile Failure
PHP Version: 7.0.15 OS: Linux x86_64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zhuravlov dot ip at ya dot ru
New email:
PHP Version: OS:

 

 [2017-01-30 17:36 UTC] zhuravlov dot ip at ya dot ru
Description:
------------
Distro: openSUSE Leap 42.1 (x86_64)

Packages used: php7-7.0.15-35.2.x86_64

Standard (not changed) php.ini

Command to run: php test-static-lambda.php


Test script:
---------------
<?php
function f1() {
  $lambda1 = function() {};  // line 3
}

function f2() {
  $lambda2 = static function() {};  // line 7
}

function f3() {
  static $lambda3 = function() {};  // line 11
}

function f4() {
  static $lambda4 = static function() {};  // line 15
}


Expected result:
----------------
Lines 11 and 15 should not produce a fatal error. BTW, I'm slightly in doubt about line 11 since it looks wrong.

Instead, lines 11 and 15 should be performed silently as lines 4 and 9 do.

Actual result:
--------------
PHP Fatal error:  Constant expression contains invalid operations in /home/user/tmp/test-static-lambda.php on line 11

If you comment out the line 11 then:

PHP Fatal error:  Constant expression contains invalid operations in /home/user/tmp/test-static-lambda.php on line 15


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-30 17:42 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-01-30 17:42 UTC] requinix@php.net
static variables must be initialized with constant values. Closures are expressions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 14:01:29 2024 UTC