Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98674 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20708 invoked from network); 30 Mar 2017 07:07:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2017 07:07:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@daveyshafik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@daveyshafik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain daveyshafik.com from 209.85.213.179 cause and error) X-PHP-List-Original-Sender: me@daveyshafik.com X-Host-Fingerprint: 209.85.213.179 mail-yb0-f179.google.com Received: from [209.85.213.179] ([209.85.213.179:36687] helo=mail-yb0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 34/04-10047-BAEACD85 for ; Thu, 30 Mar 2017 02:07:26 -0500 Received: by mail-yb0-f179.google.com with SMTP id i124so4642578ybc.3 for ; Thu, 30 Mar 2017 00:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daveyshafik-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=L/Crt7iZMseAa9AgXgvmhBLKZ7zkPW+slwgzk2qZN1o=; b=t05Kzg4V2LqkOq6bAzb79ZBZAdzP584Fhu7tghLL04v9pWTEnyhSz3eTn2JVLaMSrk JhNlN6+jL43P69zrA/367woxKN1DYAb1NgLRn8Kr+R698dvhABlM62CCP5LgbnqmgsK1 ScitLDlMVJzDbvjr2QbGKIi9YPz17ihVYecqAvno4TasPDiS2m6XkQmMS8ZmhVIViU6e EphpEig6QWn6+3rkzvJ2Bgpjj+/nqIv0RhTLD66Bg+zAq/zEY/ZxrC10WbrQdb4B7teT 51nXRrFrE41IoR1SrqdXLdbCI9IFd3W2pNfCHvTvxqPAbHCNq4vvcNpgDq5VcX5RmrwQ fapw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=L/Crt7iZMseAa9AgXgvmhBLKZ7zkPW+slwgzk2qZN1o=; b=JOueCVKO0LF0wn5b4U/eDx4k0Brph9DhR+UOWt7JQBAaDalBqudbcE6ujLFvlB5tvG dYSzBzFecDsCcKsSTUWZdXZMjtZfxD/xMuRWamK0GiGdT9P3q2IZtZRE3KSoj24lfnxx f2PYkOReh/Uy01NcQrywT9jsCOpCxFyof5dke6P+qPDfuyrn+8iZNJHDrjslDDeP+DSP biS5vIHKBhoyudnWxVCjcY8I76J2mKzBZBwt6q5cNzLrWHAvk6wAHpAzsy/6LzCh6D2u zndyMf+qVmkjyUwYkNTy0hSgdx1NWwdCbaS4CwEH625VesnDMGw17YaXN11JIJul+Z4X IJLw== X-Gm-Message-State: AFeK/H14u/CPv6o8WMV3ePHiPCXeNROhcn2x3Vwu7JKNHWrA/pYLYz3vuyM6Rzd1nSh72OdeyZR7zVYaRyuvjtHB X-Received: by 10.37.230.205 with SMTP id d196mr1137033ybh.47.1490857638978; Thu, 30 Mar 2017 00:07:18 -0700 (PDT) MIME-Version: 1.0 Sender: me@daveyshafik.com Received: by 10.129.135.3 with HTTP; Thu, 30 Mar 2017 00:07:18 -0700 (PDT) In-Reply-To: References: Date: Thu, 30 Mar 2017 00:07:18 -0700 X-Google-Sender-Auth: -gS_KkitQ0A4g6m5p6LuFW66hNY Message-ID: To: dmitr y Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=94eb2c0a8b44fb950b054bed5799 Subject: Re: [PHP-DEV] ; on the end of the line From: davey@php.net (Davey Shafik) --94eb2c0a8b44fb950b054bed5799 Content-Type: text/plain; charset=UTF-8 On Wed, Mar 29, 2017 at 11:10 PM, dmitr y wrote: > Hello, dear coders. > I'm using php for a year and it's being my favourite language. Also I'm > using some bookkeping languages which is based on php syntax but ';' on the > end of the line is not neccesary on it. > So I can't understand why syntax needs symbol ';' on the end of every line, > if it also ends by 0Ch and 0Dh. Is there a possibility to interpretate php > code without ';' on the end of the line, and make it not necessary? > > Maybe some compilation parameter or directive at code? > > Best regards, > Dmitry > Dmitry, It is not necessary to end each line with a semicolon (the ';'), it is however necessary to terminate each statement (or instruction) with one. It's very common to only have one statement per line; which is why is seems that it is required on every line. There are several places this is not the case: - Any block opening/close: e.g. if/while/for/foreach ... { // or it's close, or a comment for that matter! } - An unfinished statement: echo $foo . $bar // concat (.) operator can be here, as above, or on the next line: . $baz; // only semicolon here, to finish the statement - Preceding a closing PHP tag (?>) as this also terminates a statement: echo $foo ?> Alternatively, you may have MORE than one statement per line: - echo $foo; return $bar; - syslog(LOG_ERR, "Something went wrong!"); exit; - header("Location: /foo/bar"); exit; Notice each of these has two statements. (Note: I don't think any of these are particularly good ways to write readable code, but they are all syntactically valid code). While I know some languages make semicolons optional (javascript), or omit them entirely (python), semicolons in PHP will not be going away (or optional) any time soon. Even a language like Go where they are optional, and largely discouraged, it can be used to explicitly allow the initialization of a local (only exists in the scope of the if statement) variable prior to the condition: if err := DoSomething(); err != nil { // initialization before ; condition { return err // no semicolon necessary } I hope this helps! - Davey --94eb2c0a8b44fb950b054bed5799--