I am padding integers for barcodes with leading zeros so they have same number of characters, for example:
1 -> 00000001 12 -> 00000012 1044 -> 00001044
00000001 is numeric and when casting to an integer it is 1.
Will this work as expected for all integers?
Careful, numbers starting with 0 are treated as base 8 in PHP
however explicit casting string to int seems to be safe
You did not say anything where you’re going to be storing these numbers, but in case it will be a database, here’s some advice regarding datatype:
Barcode numbers are not (despite the name) numbers. Same goes for fax numbers, social security numbers, etc. You should not store these as numeric data (for example using MySQL’s INT or DECIMAL) datatype. Instead use textual datypes (like CHAR or VARCHAR)