This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 251224

Summary: Support for scalar type declarations for PHP 7
Product: php Reporter: naitsirch <naitsirch>
Component: EditorAssignee: junichi11
Status: RESOLVED WORKSFORME    
Severity: normal CC: TheTechFan, tmysik
Priority: P3    
Version: 8.1   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description naitsirch 2015-03-17 07:57:31 UTC
Hi.

Yesterday the RFC about "Scalar Type Declarations" has been finally accepted by the PHP developer community. The RFC could be found here: https://wiki.php.net/rfc/scalar_type_hints_v5

The names int, float, string and bool are recognised and allowed as type declarations, and prohibited from use as class/interface/trait names (including with use and class_alias).

A new declare() directive is added, strict_types, which takes either 1 or 0. If 1, strict type-checking mode is used for function calls and return statements in the the file. If 0, weak type-checking mode is used.
The declare(strict_types=1) directive must be the first statement in a file. If it appears anywhere else in the file it will generate a compiler error. Block mode is also explicitly disallowed (declare(strict_types=1); is the only allowed form). 

Example:

<?php
function add(int $a, int $b) {
    return $a + $b;
}

var_dump(add(1, 2)); // int(3)

// floats are truncated by default
var_dump(add(1.5, 2.5)); // int(3)
 
//strings convert if there's a number part
var_dump(add("1", "2")); // int(3)
?>

The RFC is very detailed. It would be great if Netbeans would support these type declarations in the next version.
Comment 1 Vebut 2015-08-03 09:20:49 UTC
Scalar types are just one of many new features in PHP 7 and this issue should be updated in line with the full RFC including scalar types, return types, anonymous classes, reserved key words, spaceship (combined comparison) and more.

PHP 7 have been accepted for a while and first release will be in November.

I propose the priority gets raised for this issue.
Comment 2 Petah 2015-09-25 04:28:11 UTC
+1 with PHP 7 looming, it would be good to get IDE support
Comment 3 trambulhao 2015-12-21 11:17:45 UTC
When there will be support php 7?
Comment 4 Petah 2016-01-12 09:56:44 UTC
Any word on this?
Comment 5 BlameFate 2016-01-12 10:02:03 UTC
@Petah:
Try the nightly build! Select PHP5.6 for your project, as there may not be a PHP7 option yet - then, NetBeans should support this feature. (Works for me!)
http://bits.netbeans.org/download/trunk/nightly/latest/
Comment 6 junichi11 2016-11-11 02:43:14 UTC
This is already fixed in NetBeans 8.2.

Thanks.