zend-barcode
zend-barcode copied to clipboard
Object reserved keyword
The object keyword became reserved in PHP 7, this conflicts with the Zend\Barcode\Object;
namespace.
http://php.net/manual/en/reserved.other-reserved-words.php
@fntlnz It doesn't. The reason is because the namespace is not Object, but Zend\Barcode\Object; our tests even pass currently on PHP 7.
Do you have a specific example demonstrating breakage?
@weierophinney The object keyword does not lead to an immediate breakage (like Int, Float and String) because is not marked as reserved in the current implementations of the PHP language (PHP, HHVM etc) but has been reserved for the future use as stated by these documentes:
- PHP Documentation here
These words cannot be used to name a class, interface or a trait. These words are also prohibited from being used in namespaces. Some of the words are reserved to enable future PHP features without breaking backward compatibility. [...followed by a table containing reserved names including object]
- PHP language specification here
The following names are reserved for future use and should not be used as the names of classes, interfaces, or traits: mixed, numeric, object, and resource.
Object is used as namespace not as class, interface or trait.
So, what's the point?
From: http://php.net/manual/en/reserved.other-reserved-words.php
These words are also prohibited from being used in namespaces
As @weierophinney point the namespace is the whole string. PHP does not distinguish namespace parts.
Probably namespace Object {} may fail due the restrictions you noticed but not Foo\<any restricted word>
Anyway if you found a better term for name the namespace we could consider start to use it in the next minor version (preserving the old namespace for BC)
Hello @fntlnz :)
We can start to use a new name ( and mark this class as deprecated in order to remove it during 3.0 release
- Zend\Barcode\BarcodeObject
- Zend\Barcode\Barcode
Minimal fix in https://github.com/zendframework/zend-barcode/pull/36
Hi, we are also seeing this issue in PHP 7.2
PHP Fatal error: Cannot use Zend\Barcode\Object as Object because 'Object' is a special class name in www/vhosts/api.content-manager/src/PhysicalLookbook/Service/PdfGenerator.php on line 26
Line 26: use Zend\Barcode\Object;
Any help very welcome.
Thks
@dbarn Which version of zend-barcode do you use?
~~Fixed with #36 and released with version 2.6.1~~
Related to #37
Hi we are using 2.7 I have fixed by aliasing the object in our code: Line 26: use Zend\Barcode\Object as BarcodeObject
And then using $barcode = new Object\Ean13();
This work ok.
@dbarn Thanks for your feedback!
I will reopen this issue, because the problem with Object in namespace was not fixed and must be done on version 3.0!
This repository has been closed and moved to laminas/laminas-barcode; a new issue has been opened at https://github.com/laminas/laminas-barcode/issues/1.