Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3664658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:40:18+00:00 2026-05-19T01:40:18+00:00

Why can such code as pack(‘i’,6) return 0? All php.net says about return values

  • 0

Why can such code as pack('i',6) return 0?

All php.net says about return values of this function:

Returns a binary string containing
data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:40:19+00:00Added an answer on May 19, 2026 at 1:40 am

    You have to be a bit more specific here. What’s the return type? It’s a binary string, so often what you see is not what it actually contains.

    It could start with a few null bytes (i.e. value=0, \0 char). Since this byte is used to denote string ends in C and other languages, echo and other functions stop when they encounter a null byte (sometimes the manual says a function is ‘binary-safe’, which means it does not consider a null byte as string end).

    Also there are a lot of non-printable characters. They usually have some kind of special meaning (for example character 7 is the “bell” command, type this into your shell to try it out php -r 'echo "\7";').

    To find out what’s in your string, you could “convert” each char to its hexadecimal representation. You can use bin2hex() for this, note that it needs two chars to represent one char of the input string.

    $ php -r 'var_dump(bin2hex(pack("i",6)));'
    string(8) "06000000"
    

    (The output you see above depends on your hardware.) In my case pack('i', 6); returns the integer in little-endian format, since I’ve got an Intel processor.

    You can see that the first char (06) has the decimal value 6. What you then do is usually look up which character this belongs to. In many cases it’s okay to use an ASCII table, but note that in case you’re using unicode or any other encoding certain characters could have another meaning. According to my ASCII table, it’s the ACK character. It’s a non-printable character, it has control function only.

    What remains to be explained is why this translates to integer 0. Fortunately that’s very easy. Read the PHP manual page on casting strings to numbers.

    If the string starts with valid
    numeric data, this will be the value
    used. Otherwise, the value will be 0
    (zero).

    Since the \6 char is neither a sign nor a digit (the chars 0-9 are decimal \48–\57 or \0x30–\0x39 hexadecimal) PHP returns zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally, you can use code such as this to validate incoming data: $post =
How can I implement a diff function, such as Stack Overflow's question revision history?
Can Html Agility Pack be used to parse an html string fragment? Such As:
I have one question, I have such code this._engine = Python.CreateEngine(); ScriptSource source =
i'v got such code function EnDeCrypt($text, $key, $s = 1){ $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
This is not a question about real code, it is just for discussion. It
Ive got ASP.NET web application form where users enter details such as: Subject Code
I'm still getting used to the sizers in wxWidgets, and as such can't seem
I see in MSDN links such as CompareOrdinal Overloads. How can I write such
Is there such a thing as an x86 assembler that I can call through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.