This is a followup of this question this question.
@Corbin @Corbin made a very interesting review very interesting review, and I re-wrote most of the code.
This is a followup of this question.
@Corbin made a very interesting review, and I re-wrote most of the code.
This is a followup of this question.
@Corbin made a very interesting review, and I re-wrote most of the code.
PHP function to create a Hex dump - FollowupFollow up
This is a followup of the following question: PHP function to create a Hex dumpthis question .
List of actions taken, based on @Cobin's@Corbin's review:
I've created the closure
$to_hex
, which handles almost all the hexadecimal conversions and padding.Tried to DRY my code as much as possible, but kindly ignored his suggestion to call it recursively.
That wasn't the goal: The goal is to receive an array of bytes, not an array of arbitrary values.
I've created the closure$to_hex
, which handles almost all the hexadecimal conversions and padding.- Tried to DRY my code as much as possible, but kindly ignored his suggestion to call it recursively.
That wasn't the goal: The goal is to receive an array of bytes, not an array of arbitrary values.
Regarding performance, I've replaced all the
array_walk
calls withforeach()
loops.Also, I've tried to remove as many calls to
str_split
as possible.I've separated the multiple
echo
es and it is a lot clearer now.Even though his last advice was really good, the goal isn't to return
return
the hex dump.The idea is to use it like how we use
var_dump
.
With those actions taken and the changes made, now it's time to ask:
- What else can I improve?
- Is there any other performance killerkillers?
- Is my code DRY now?
- Is it more easily readable?
PHP function to create a Hex dump - Followup
This is a followup of the following question: PHP function to create a Hex dump
List of actions taken, based on @Cobin's review:
I've created the closure
$to_hex
, which handles almost all the hexadecimal conversions and padding.Tried to DRY my code as much as possible, but kindly ignored his suggestion to call it recursively.
That wasn't the goal: The goal is to receive an array of bytes, not an array of arbitrary values.
Regarding performance, I've replaced all the
array_walk
calls withforeach()
loops.Also, I've tried to remove as many calls to
str_split
as possible.I've separated the multiple
echo
es and it is a lot clearer now.Even though his last advice was really good, the goal isn't to return the hex dump.
The idea is to use it like how we use
var_dump
.
With those actions taken and the changes made, now it's time to ask:
- What else can I improve?
- Is there any other performance killer?
- Is my code DRY now?
- Is it more easily readable?
PHP function to create a Hex dump - Follow up
This is a followup of this question .
List of actions taken, based on @Corbin's review:
- I've created the closure
$to_hex
, which handles almost all the hexadecimal conversions and padding. - Tried to DRY my code as much as possible, but kindly ignored his suggestion to call it recursively.
That wasn't the goal: The goal is to receive an array of bytes, not an array of arbitrary values.
Regarding performance, I've replaced all the
array_walk
calls withforeach
loops.Also, I've tried to remove as many calls to
str_split
as possible.I've separated the multiple
echo
es and it is a lot clearer now.Even though his last advice was really good, the goal isn't to
return
the hex dump.The idea is to use it like how we use
var_dump
.
With those actions taken and changes made, now it's time to ask:
- What else can I improve?
- Is there any other performance killers?
- Is my code DRY now?
- Is it more easily readable?
<br /> <b>Warning</b>: hex_dump() invalid value on index 0 in <b>/code/3kGyEY</b> on line <b>65</b><br /> <br /> <b>Warning</b>: hex_dump() strings in a byte array cannot have more than 1 character on index 1 in <b>/code/3kGyEY</b> on line <b>58</b><br /> <br /> <b>Warning</b>: hex_dump() numbers in a byte array cannot be higher than 255 on index 2 in <b>/code/3kGyEY</b> on line <b>50</b><br /> |00|01|02|03|04|05|06|07|08|09|0a|0b|0c|0d|0e|0f| TEXT -------------------------------------------------------------------- 00 |--|74|39| | | | | | | | | | | | | |�t9 ==================================================================== Lines: 1 | Bytes: 3 | Time: 0.00012302398681641ms
<br /> <b>Warning</b>: hex_dump() invalid value on index 0 in <b>/code/3kGyEY</b> on line <b>65</b><br /> <br /> <b>Warning</b>: hex_dump() strings in a byte array cannot have more than 1 character on index 1 in <b>/code/3kGyEY</b> on line <b>58</b><br /> <br /> <b>Warning</b>: hex_dump() numbers in a byte array cannot be higher than 255 on index 2 in <b>/code/3kGyEY</b> on line <b>50</b><br /> |00|01|02|03|04|05|06|07|08|09|0a|0b|0c|0d|0e|0f| TEXT -------------------------------------------------------------------- 00 |--|74|39| | | | | | | | | | | | | |�t9 ==================================================================== Lines: 1 | Bytes: 3 | Time: 0.00012302398681641ms
- I've created the closure
$to_hex
, which handles almost all the hexadecimal conversions and padding.I've created the closure
$to_hex
, which handles almost all the hexadecimal conversions and padding. - Tried to DRY my code as much as possible, but kindly ignored his suggestion to call it recursivelly.
Tried to DRY my code as much as possible, but kindly ignored his suggestion to call it recursively.
That wasn't the goal: The goal is to receive an array of bytes, not an array of arbitrary values.That wasn't the goal: The goal is to receive an array of bytes, not an array of arbitrary values.
- Regarding performance, I've replaced all the
array_walk
calls withforeach()
loops.Regarding performance, I've replaced all the
Also, I've tried to remove as many calls toarray_walk
calls withforeach()
loops.str_split
as possible.Also, I've tried to remove as many calls to
str_split
as possible. - I've separated the multiple
echo
es and it is a lot clearer now.I've separated the multiple
echo
es and it is a lot clearer now. - Even though his last advice was really good, the goal isn't to return the hex dump.
Even though his last advice was really good, the goal isn't to return the hex dump.
The idea is to use it like how we usevar_dump
.The idea is to use it like how we use
var_dump
.
- What else can I improve?
- Is there any other performance killer?
- Is my code DRY now?
- Is it more easily readable?
<br /> <b>Warning</b>: hex_dump() invalid value on index 0 in <b>/code/3kGyEY</b> on line <b>65</b><br /> <br /> <b>Warning</b>: hex_dump() strings in a byte array cannot have more than 1 character on index 1 in <b>/code/3kGyEY</b> on line <b>58</b><br /> <br /> <b>Warning</b>: hex_dump() numbers in a byte array cannot be higher than 255 on index 2 in <b>/code/3kGyEY</b> on line <b>50</b><br /> |00|01|02|03|04|05|06|07|08|09|0a|0b|0c|0d|0e|0f| TEXT -------------------------------------------------------------------- 00 |--|74|39| | | | | | | | | | | | | |�t9 ==================================================================== Lines: 1 | Bytes: 3 | Time: 0.00012302398681641ms
- I've created the closure
$to_hex
, which handles almost all the hexadecimal conversions and padding. - Tried to DRY my code as much as possible, but kindly ignored his suggestion to call it recursivelly.
That wasn't the goal: The goal is to receive an array of bytes, not an array of arbitrary values. - Regarding performance, I've replaced all the
array_walk
calls withforeach()
loops.
Also, I've tried to remove as many calls tostr_split
as possible. - I've separated the multiple
echo
es and it is a lot clearer now. - Even though his last advice was really good, the goal isn't to return the hex dump.
The idea is to use it like how we usevar_dump
.
- What else can I improve?
- Is there any other performance killer?
- Is my code DRY now?
- Is it more easily readable?
<br /> <b>Warning</b>: hex_dump() invalid value on index 0 in <b>/code/3kGyEY</b> on line <b>65</b><br /> <br /> <b>Warning</b>: hex_dump() strings in a byte array cannot have more than 1 character on index 1 in <b>/code/3kGyEY</b> on line <b>58</b><br /> <br /> <b>Warning</b>: hex_dump() numbers in a byte array cannot be higher than 255 on index 2 in <b>/code/3kGyEY</b> on line <b>50</b><br /> |00|01|02|03|04|05|06|07|08|09|0a|0b|0c|0d|0e|0f| TEXT -------------------------------------------------------------------- 00 |--|74|39| | | | | | | | | | | | | |�t9 ==================================================================== Lines: 1 | Bytes: 3 | Time: 0.00012302398681641ms
I've created the closure
$to_hex
, which handles almost all the hexadecimal conversions and padding.Tried to DRY my code as much as possible, but kindly ignored his suggestion to call it recursively.
That wasn't the goal: The goal is to receive an array of bytes, not an array of arbitrary values.
Regarding performance, I've replaced all the
array_walk
calls withforeach()
loops.Also, I've tried to remove as many calls to
str_split
as possible.I've separated the multiple
echo
es and it is a lot clearer now.Even though his last advice was really good, the goal isn't to return the hex dump.
The idea is to use it like how we use
var_dump
.
- What else can I improve?
- Is there any other performance killer?
- Is my code DRY now?
- Is it more easily readable?