zend-barcode icon indicating copy to clipboard operation
zend-barcode copied to clipboard

Object reserved keyword

Open fntlnz opened this issue 9 years ago • 14 comments

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 avatar Dec 17 '15 15:12 fntlnz

@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 avatar Feb 17 '16 21:02 weierophinney

@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.

fntlnz avatar Feb 18 '16 08:02 fntlnz

Object is used as namespace not as class, interface or trait.

Maks3w avatar Feb 18 '16 09:02 Maks3w

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

fntlnz avatar Feb 18 '16 09:02 fntlnz

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)

Maks3w avatar Feb 18 '16 09:02 Maks3w

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

gianarb avatar Feb 18 '16 09:02 gianarb

Minimal fix in https://github.com/zendframework/zend-barcode/pull/36

remicollet avatar Oct 20 '17 11:10 remicollet

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 avatar Nov 09 '18 12:11 dbarn

@dbarn Which version of zend-barcode do you use?

froschdesign avatar Nov 09 '18 12:11 froschdesign

~~Fixed with #36 and released with version 2.6.1~~

froschdesign avatar Nov 09 '18 12:11 froschdesign

Related to #37

froschdesign avatar Nov 09 '18 12:11 froschdesign

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 avatar Nov 09 '18 12:11 dbarn

@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!

froschdesign avatar Nov 09 '18 12:11 froschdesign

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.

weierophinney avatar Dec 31 '19 21:12 weierophinney