php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52432 {} with Return Value
Submitted: 2010-07-25 02:09 UTC Modified: 2010-08-16 22:14 UTC
From: halloanjedendenichkenne at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: halloanjedendenichkenne at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-25 02:09 UTC] halloanjedendenichkenne at gmail dot com
Description:
------------
It would be pretty cool if you were able to use { CodeHere; } as Statement.
The Basic Idea behind this is like if the Code was a Function that had a Return 
Statement. Its only a little inefficient because the Function might only be used 
one Time, which means it would be useful to have such a Feature.

Examples are given in the TestScript

Test script:
---------------
<?php

  //1.
  if({
    $a = false;
    $b = true;
    return (time() % 2) && $b || $a;
  }) echo 'It equals to True';

  //2.
  mysql_connect(...) or {
    $file = fopen('ErrorLog', 'a+');
    ...;
    return die();
  };

  //3.
  $a = 12 + {
    return 2 * 2;
  };

?>

Expected result:
----------------
1. Depending on the Time echoing 'It equals to True';
2. When mysql_connect returns false that it evaluates the {}-Code
3. $a = 16;

Actual result:
--------------
Parse Error of course

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-16 22:14 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2010-08-16 22:14 UTC] kalle@php.net
Closures here should really be enough for what you are trying to achieve:
http://php.net/closures

As for the function-call-or-failure sample, if you really want such a context then I do not see why you don't simply do:

if(!call(...)) {
        ...
]
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 14:01:32 2025 UTC