What will var_dump(1...9) output? The following article will analyze it for you. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
A question, var_dump(1...9)
What is the output?
Verify it by hand:
php -r “var_dump(1...9)”; string(4) ”10.9“
Output 10.9. At first glance, the output of this var_dump seems strange, right? why?
Here we will teach you, if you see a piece of PHP code and feel that the output is strange, the first reaction is to see what the opcodes generated by this code are. Although this problem is actually a problem in the lexical analysis stage, but still use Let's analyze it with phpdbg (usually in order to prevent the influence of opcache, -n will be passed):
phpdbg -n -p /tmp/1.php function name: (null) L1-35 {main}() /tmp/1.php - 0x7f56d1a63460 + 4 ops L2 #0 INIT_FCALL<1> 96 "var_dump" L2 #1 SEND_VAL "10.9" 1 L2 #2 DO_ICALL L35 #3 RETURN<-1> 1
So it seems that long before the opcode is generated, 1...9 becomes the constant 10.9, considering This is a literal value. Let’s take a look at zend_language_scanner.l and find this line:
DNUM ({LNUM}?"."{LNUM})|({LNUM}"."{LNUM}?)
This is the format of floating point numbers defined by lexical analysis. It suddenly dawned on us at this point:
1 ...9 will be accepted in sequence as: 1. (floating point number 1), then . (string concatenation symbol) and then .9 (floating point number 0.9)
so it will be generated directly during the compilation phase "1" . "0.9" -> String literal "10.9"
Okay, here, this little "puzzle" is explained clearly.
Of course, this is not only defined in PHP, almost all languages will define this abbreviated floating-point form. Sometimes in C language, in order to input a floating-point integer, we can Use for example 1. to tell the compiler that this is a floating point number.
However, firstly, it happens to be in PHP. The number has another meaning, which is string concatenation. Secondly... in PHP5.6 Then there is a new operator called the Splat operator, which can be used to define variable parameter functions or solve arrays, for example,
<?php function foo($a, $b, $c) { var_dump($a + $b + $c); } $parameters = array (1, 2, 3); foo(...$parameters); ?>
So, at first glance, this leads to this confusing result
Recommended learning: PHP video tutorial
The above is the detailed content of What will php's var_dump(1...9) output?. For more information, please follow other related articles on the PHP Chinese website!

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use
