php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76036 Preprocessor directives
Submitted: 2018-03-01 08:44 UTC Modified: 2018-03-01 09:13 UTC
From: obadja dot hauser at gmail dot com Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: Irrelevant OS: ALL
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-03-01 08:44 UTC] obadja dot hauser at gmail dot com
Description:
------------
In some cases can i need this feature.
I think, this was a possible way to made code to running with modern features PHP >= 7 and on old Versions. Or to write fine granular code. Or transparence and clearer code.


The preprocessor directives should recognized following:
- #<preprocessor type> <preprocessor identifier> <
- <preprocessor type>: #IF, #IFNOT followed by #ENDIF. Between ca #ELSE or/and #ELSEIF
- <preprocessor identifier>: PHPVAR (PHP Version), OSVAR (OS Version), OS (OS Name), HTTPSRV (Webserver Name) and CLI (if true if running via cli command). It should possible to concatenate with AND. 
- <comparer>: <,<=,>,>=,= (= if the default comparer an is not needed to write it)
- <compare value>: will always interpreted as string or number for the compare var



Is there this feature planned or on your todo list :)

Test script:
---------------
My idea was so, e.g. class function:

#IF PHPVER >= 8.0
public function getAndCatchMethod(string $methodname) : callable on throws \MyException
#ELSE
public function getAndCatchMethod(string $methodname) : callable
#ENDIF
{
    return [$this, $methodname];
}

Expected result:
----------------
Code dynamical builded on preprocessor directives.

#IF PHPVER >= 8.0
public function getMagic(string $value = '') : callable on throws \MyException
{
   # this new killer feature will catching the Exception automatically to given Exception Class without to need try..catch, if method called ;)
   return [$this, $methodname];
}

Class->getAndCatchMethod('test')
MyException::catch() {}

#ELSE

public function getAndCatchMethod(string $methodname) : callable
{
   # regular exception catching
   return [$this, $methodname];
}

try { Class->getAndCatchMethod('test') } catch (...) { }

Actual result:
--------------
Nothing. This will not working at this time.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-01 09:13 UTC] requinix@php.net
-Summary: Preporocessor directrives +Summary: Preprocessor directives -Status: Open +Status: Suspended -Package: *Programming Data Structures +Package: Scripting Engine problem
 [2018-03-01 09:13 UTC] requinix@php.net
Thank you for your interest in PHP and for submitting a feature
request. Please be aware that due to the magnitude of change this
request requires, it would be necessary to discuss it on PHP
Internals list (internals@lists.php.net) as an RFC. Please read
the guide about creating RFCs here:
<https://wiki.php.net/rfc/howto>. If you haven't had experience
with writing RFCs before, it is advised to seek guidance on the
Internals list (<http://php.net/mailing-lists.php>) and/or solicit
help from one of the experienced developers.

Please something something this comment something a view on the
merits of your proposal – every proposal which requires changes of
certain magnitude, even the very successful and widely supported
ones, must be done through the RFC process. This helps make the
process predictable, transparent and accessible to all developers.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC