English 中文(简体)
哪怕是PHP中最简单的类别——Am I正在疯狂? [闭门]
原标题:Can t declare even the most simple class in PHP - Am I going insane? [closed]

每当我试图宣布一个等级时,就会出现这一错误:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or
T_FUNCTION or T_VAR or  }  in /home3/foundloc/public_html/booka/page2.php
on line 7 (line 7 is the class declaration by the way).

我在此试图宣布:

Class abc
{

$a = “Hello!”;

} 

是否在需要转向的购买力平价上有一些条件? 我感到,如果电视在问题类型上挂牌,那是你检查的。

最佳回答

你们可以宣布这种类型的财产。 某类人员可以是数据成员(客户和财产)或方法。 在PHP 5型做事方式中,这基本上是它如何运作:

// de facto best practice: class names start with uppercase letter
class Abc
{
    // de facto best practice: ALL UPPERCASE letters for constants
    const SOME_COSTANT =  this value is immutable ; // accessible outside and inside this class like Abc::SOME_CONSTANT or inside this class like self::SOME_CONSTANT

    public $a =  Hello ; // a data member that is accessible to all
    protected $b =  Hi ; // a data membet that is accessible to this class, and classes that extend this class
    private $c =  Howdy ; // a data member that is accessible only to this class

    // visibility keywords apply here also
    public function aMethod( $with, $some, $parameters ) // a method
    {
        /* do something */
    }
}

确实,你不应考虑使用第4号站点的做法,即用<代码>var的关键词宣布数据成员,除非你仍在为第4号站点开发数据。

问题回答

提 出

class abc {
  public $a = "Hello!";
} 

class abc {
  var $a = "Hello!";
} 

审判

<?php
Class abc {
   var $a = "Hello!";
}
?>

应开展工作。 您必须用var <>/em>或public<>/em>或 private加上static关键词来说明该成员的可见度。

应在描述特性的加拿大人网页





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...