PHP class constructor?

I'm useed to object orientated programming (C#) so now I'n switching to php its time to write classes. But there's something I don't get in the following code:
<?php
Class path{
    private $serverPath;
    function _construct()
        $this->serverPath = $_SERVER['DOCUMENT_ROOT'];
    public function getServerpath()
        return $this->serverPath;
    public function rel2abs ($relpath)
        if (substr($relpath,0) != "/") $relpath = "/".$relpath;
        $relpath = $this->serverPath .$relpath;
        return realpath($relpath);   
?>
After debugging it appears that after the object is constructed the private value $serverPath remains NULL ?

M.R.Biesheuvel wrote:
 After debugging it appears that after the object is constructed the private value $serverPath remains NULL ?
That's because of an error in your code. The constructor method in a PHP class begins with TWO underscores.
function __construct()
In your code, there's only one underscore.

Similar Messages

  • New Document Type Template PHP Class

    How do I create a new document type template for a PHP class
    in Dreamweaver CS3?
    I want to be able to go File -> New -> Blank Page ->
    PHP Class.
    I want the template to then look like:
    [code]
    <?php
    class Classname {
    //Class Member Variables
    //Constructor
    public function Classname() {
    //Methods
    ?>
    [/code]
    Thanks.

    Bumb, anybody?

  • Can Some One Help With A PHP Class?

    I have a simple function and I can not for the life of me get it to work properly. Here's the PHP:
    <?php
    class userProjectNotes {
              var $username = "user";
              var $password = "secret";
              var $server = "url-here.net";
              var $port = "3306";
              var $databasename = "mscoast";
              var $connection;
              public function __construct() {
                          $this->connection = mysqli_connect(
                                                                                      $this->server, 
                                                                                      $this->username, 
                                                                                      $this->password,
                                                                                      $this->databasename,
                                                                                      $this->port
                        $this->throwExceptionOnError($this->connection);
               * Gets all my stuffs from the places... Yeah... You get it...
              public function getAlluserProjectnotes($userTable) {
                        $stmt = mysqli_prepare($this->connection, "SELECT * FROM $userTable");
                        $this->throwExceptionOnError();
                        mysqli_stmt_execute($stmt);
                        $this->throwExceptionOnError();
                        $rows = array();
                        mysqli_stmt_bind_result($stmt, $row->notes_id, $row->date_added, $row->note, $row->pid);
                  while (mysqli_stmt_fetch($stmt)) {
                    $rows[] = $row;
                    $row = new stdClass();
                    mysqli_stmt_bind_result($stmt, $row->notes_id, $row->date_added, $row->note, $row->pid);
                        mysqli_stmt_free_result($stmt);
                  mysqli_close($this->connection);
                  return $rows;
    ?>
    ( I ommited the ThrowexceptionOnError to save space in this post.
    And here is my call to it:
    protected function list_creationCompleteHandler():void
                                            userProjectNotes.endpoint = "http://www.url-here.net/app-resources/gateway.php";
                                            getAlluserProjectnotesResult.token = userProjectNotes.getAlluserProjectnotes(userNotesTable);
    it works locally, but remotely I get:
    Channel disconnected before an acknowledgement was received

    Yup yup! My other services are working fine. just this one service is causing the issue...
    [zend]
    ;set the absolute location path of webroot directory, example:
    ;Windows: C:\apache\www
    ;MAC/UNIX: /user/apache/www
    webroot =/var/www/url-here.net/web/app-resources
    ;set the absolute location path of zend installation directory, example:
    ;Windows: C:\apache\PHPFrameworks\ZendFramework\library
    ;MAC/UNIX: /user/apache/PHPFrameworks/ZendFramework/library
    zend_path = /var/www/url-here.net/web/app-resources/ZendFramework/library
    [zendamf]
    amf.production = false
    amf.directories[]=services

  • How to inherit super class constructor in the sub class

    I have a class A and class B
    Class B extends Class A {
    // if i use super i can access the super classs variables and methods
    // But how to inherit super class constructor
    }

    You cannot inherit constructors. You need to define all the ones you need in the subclass. You can then call the corresponding superclass constructor. e.g
    public B() {
        super();
    public B(String name) {
        super(name);
    }

  • More:Could u pls complete the following code by adding a class constructor?

    Thank you for your concern about my post. Actually it is an exercise in book "Thinking in Java, 2nd edition, Revision 12" chapter 8. The exercise is described as below:
    Create a class with an inner class that has a nondefault constructor. Create a second class with an inner class that inherits from the first inner class.
    And I make some changes for the above exercise requiring the class which encloses the first inner class has a nondefault constructor.
    There is something related to this topic in chapter 8 picked out for reference as below:
    Inheriting from inner classes
    Because the inner class constructor must attach to a reference of the enclosing class object, things are slightly complicated when you inherit from an inner class. The problem is that the �secret?reference to the enclosing class object must be initialized, and yet in the derived class there�s no longer a default object to attach to. The answer is to use a syntax provided to make the association explicit:
    //: c08:InheritInner.java
    // Inheriting an inner class.
    class WithInner {
    class Inner {}
    public class InheritInner
    extends WithInner.Inner {
    //! InheritInner() {} // Won't compile
    InheritInner(WithInner wi) {
    wi.super();
    public static void main(String[] args) {
    WithInner wi = new WithInner();
    InheritInner ii = new InheritInner(wi);
    } ///:~
    You can see that InheritInner is extending only the inner class, not the outer one. But when it comes time to create a constructor, the default one is no good and you can�t just pass a reference to an enclosing object. In addition, you must use the syntax
    enclosingClassReference.super();
    inside the constructor. This provides the necessary reference and the program will then compile.
    My previous post is shown below, could you help me out?
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //Could you please help me complete the following code by generating
    // the Test class constructor to ensure error free compilation? Please
    // keep the constructor simple just to fulfill its basic functionality
    // and leave the uncommented part untouched.
    class Outer {
    Outer (int i) {
    System.out.println("Outer is " + i);
    class Inner {
    int i;
    Inner (int i) {
    this.i = i;
    void prt () {
    System.out.println("Inner is " + i);
    public class Test extends Outer.Inner {
    // Test Constructor
    // is implemented
    // here.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    Test(Outer o, int i) {
      o.super(i);
    }Note that this doesn't quite answer the question from Thinking In Java, since your Test class is not an inner class (though there is no difference to the constructor requirements if you do make it an inner class).

  • Set fields of derived class in base class constructor via reflection?

    Does the Java Language Specification explicitly allow setting of fields of a derived class from within the base class' constructor via reflection? The following test case runs green, but I would really like to know if this Java code is compatible among different VM implementations.
    Many thanks for your feedback!
    Norman
    public class DerivedClassReflectionWorksInBaseClassConstructorTest extends TestCase {
    abstract static class A {
        A() {
            try {
                getClass().getDeclaredField("x").setInt(this, 42);
            } catch (Exception e) {
                throw new RuntimeException(e);
    static class B extends A {
        int x;
        B() {
        B(int x) {
            this.x = x;
    public void testThatItWorks() {
        assertEquals(42, new B().x);
        assertEquals(99, new B(99).x);
    }

    why not just put a method in the superclass that the subclasses can call to initialize the subclass member variable?In derived classes (which are plug-ins), clients can use a field annotation which provides some parameter metadata such as validators and the default value. The framework must set the default value of fields, before the class' initializer or constructors are called. If the framework would do this after derived class' initializer or constructors are called, they would be overwritten:
    Framework:
    public abstract class Operator {
        public abstract void initialize();
    }Plug-In:
    public class SomeOperator extends Operator {
        @Parameter(defaultValue="42", interval="[0,100)")
        double threshold;
        @Parameter(defaultValue="C", valueSet="A,B,C")
        String mode;
        public void setThreshold(double threshold) {this.threshold = threshold;}
        public void setMode(String mode) {this.mode = mode;}
        // called by the framework after default values have been set
        public void initialize() {
    }On the other hand, the default values and other metadata are also used to create GUIs and XML I/O for the derived operator class, without having it instantiated. So we cannot use the initial instance field values for that, because we don't have an instance.

  • Is it possible to override super class constructor?

    Is it possible to override super class constructor form subclass?

    However, you can achieve do something that looks similar to overriding.
    class Parent {
      Parent(int i, String s) {
        // do stuff
    class Child extends Parent {
      Child(int i, String s) {
        super(i, s);
        // do Child stuff here
    new Parent(1, "abc");
    new Child(2, "xyz");Although that's not overriding, it sort of looks similar. Is this what you were talking about?

  • Reference to enclosing instance in inner class constructor

    Is there any Java compiler which assigns reference to enclosing instance in constructor of inner clase before invoking super class constructor?
    class Outer {
    class Inner extends Global {
    public Inner(int x) {
    // I want (Outer.this != null) here
    super();
    class Global {
    public Global(int x) {

    class Outer {
    class Inner extends Global {
    public Inner(int x) {
    // I want (Outer.this != null) hereOuter.this is never null at this point. A non-static
    inner class always has an implicit reference to an
    instance of the enclosing class.Try this:
    class Outer {
    int m;
    class Inner extends Global {
    public Inner(int x) {
    super(x);
    protected void init(int x) {
    xxx = Outer.this.m + x; // Null pointer exception!!!
    class Global {
    int xxx;
    public Global(int x) {
    init(x);
    protected void init(int x) {
    xxx = x;

  • Php classes in dreamweaver?

    hi,
    is it possible to use php classes, includes, extends etc. in
    dreamweaver? i learned to program in php at school this way, but at
    my work (training cource) i have to use dreamwaver, including its
    behaviours, so other people can change my pages using the design
    mode of dreamweaver.
    What i would like is to make php classes with dreamweavers
    behaviors in it, and that those are showed in the design mode, and
    could be changed. (i know the live data function, but i cant edit
    in it.)
    an other thing that chould change i think is the way html is
    build up in php by dreamweaver, becouse everytime closing and
    opening php is not the way it should be in php. i hope i could get
    some advice here.
    Bart

    VolgensBartjes wrote:
    > is it possible to use php classes, includes, extends
    etc. in dreamweaver?
    You can write and use any PHP code in Dreamweaver. You can
    also edit the
    PHP code generated by Dreamweaver server behaviors. However,
    once you
    edit the server behavior code, you can no longer control the
    server
    behaviors through the Dreamweaver dialog boxes.
    David Powers
    Adobe Community Expert, Dreamweaver
    http://foundationphp.com

  • How to update the PHP Class Service back in Flash Builder 4

    I'm not sure if my post title makes any sense or not but let me explain.  I've been working on an application in Flash Builder 4 using the ZendFramework and PHP services and everything is work great. the problem I have is after I make changes to my services PHP class (edit php file that has my functions in it), how to I updated those functions in the Flash builder application?
    For example, I needed to pass a second object into one of my function in my PHP class and after I edited the file and saved it, I don't see the changes in the Flash builder 4 application. Is there a button I can run to update the PHP class back in Flash Builder?
    Thanks,
    John Baranowski

    How do you use Flash Builder to regenerate the code for the same PHP service I connected to prior? When I first connected to the PHP service Flash Builder automatically built a package with all kinds of actionscript functions in it. I added a function to my PHP Class file server side and I need help on how to update the package back in Flex to see my new function. Can anyone help me??
    -John

  • Class field initialization outside class constructor

    Hi,
    what are the benefits of initializing a class field outside the class constructor? I use this for fields, that i do not need to pass parameter to via the constructor. The code seems more clear/easy to read.

    Hi,
    what are the benefits of initializing a class field
    outside the class constructor? I use this for
    fields, that i do not need to pass parameter to via
    the constructor.
    The code seems more clear/easy to read.That's a pretty big benefit.
    For another, consider when you have multiple constructors: you've factored
    common code out of them (good) and made it impossible to forget to
    initialize that field later when, later on, you write another constructor(also good).

  • Constructor and Class constructor

    Hi all
    Can any one explain me the functionality about Constructor and class constructor??
    As well as normal methods, which you call using CALL METHOD, there are two special methods
    called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you
    create an object (CONSTRUCTOR) or when you first access the components of a class
    (CLASS_CONSTRUCTOR)
    I have read the above mentioned document from SAP Documents but i found it bit difficult to understand can any one please help me on this??
    Thanks and Regards,
    Arun Joseph

    Hi,
    Constructor
    Implicitly, each class has an instance constructor method with the reserved name constructor and a static constructor method with the reserved name class_constructor.
    The instance constructor is executed each time you create an object (instance) with the CREATE OBJECT statement, while the class constructor is executed exactly once before you first access a class.
    The constructors are always present. However, to implement a constructor you must declare it explicitly with the METHODS or CLASS-METHODS statements. An instance constructor can have IMPORTING parameters and exceptions. You must pass all non-optional parameters when creating an object. Static constructors have no parameters.
    Class Constructor
    The static constructor is always called CLASS_CONSTRUCTER, and is called autmatically before the clas is first accessed, that is before any of the following actions are executed:
    Creating an instance using CREATE_OBJECT
    Adressing a static attribute using ->
    Calling a ststic attribute using CALL METHOD
    Registering a static event handler
    Registering an evetm handler method for a static event
    The static constructor cannot be called explicitly.
    For better understanding check the following code:
    REPORT  z_constructor.
          CLASS cl1 DEFINITION
    CLASS cl1 DEFINITION.
      PUBLIC SECTION.
        METHODS:
          add,
          constructor IMPORTING v1 TYPE i
                                v2 TYPE i,
          display.
        CLASS-METHODS:
         class_constructor.
      PRIVATE SECTION.
        DATA:
        w_var1   TYPE i,
        w_var2   TYPE i,
        w_var3   TYPE i,
        w_result TYPE i.
    ENDCLASS.                    "cl1 DEFINITION
          CLASS cl1 IMPLEMENTATION
    CLASS cl1 IMPLEMENTATION.
      METHOD constructor.
        w_var1 = v1.
        w_var2 = v2.
      ENDMETHOD.                    "constructor
      METHOD class_constructor.
        WRITE:
        / 'Tihs is a class or static constructor.'.
      ENDMETHOD.                    "class_constructor
      METHOD add.
        w_result = w_var1 + w_var2.
      ENDMETHOD.                    "add
      METHOD display.
        WRITE:
        /'The result is =  ',w_result.
      ENDMETHOD.                    "display
    endclass.
    " Main program----
    data:
      ref1 type ref to cl1.
    parameters:
      w_var1 type i,
      w_var2 type i.
      start-of-selection.
      create object ref1 exporting v1 = w_var1
                                  v2 = w_var2.
       ref1->add( ).
       ref1->d isplay( ).
    Regards,
    Anirban Bhattacharjee

  • Don't need call to super class constructor

    Hi, I have
    class A {
    public A() { System.out.println("in A()");}
    public class B extends A
    { public B() {
    System.out.println("in B()");}
    public static void main( String args[] ) {
    B b = new B();}
    I don't want the super class constructor to be called... What to do? Please tell me solution other than usage of parameterised constructor?

    I don't want the super class constructor to be called... What to do? Can't be done. One of the constructors of the super class must be invoked. (Implicitly or explicitly)
    Kaj

  • Can defualt inherited the Super Class constructor to sub class ?

    Hi,
    is it passible to inherit the super class constructor by defualt when extends the super class.
    Thanks
    MerlinRoshina

    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Does FB for PHP no longer generate sample php class?

    Before on Flash 4 and 4.5
    Now on FB4.5 for PHP...
    Does this mean we have 'do the arithmertic' to write the classes instead of just expanding off the generated code?

    Sure, but I am going to use this article in my answer which describes the full workflow http://www.adobe.com/devnet/flash-builder/articles/introducing-flashbuilder45-php.html
    after you create a project and write your service as a PHP class, you should right click in the Explorer on the PHP class and select "Create PHP Service for Flex".
    This is the relevant part in the article:
    1.       Right-click the file with the class that you want to introspect and select Create PHP Service for Flex (see Figure 3).
    Figure 3. Selecting Create PHP Service For Flex to introspect a PHP class.
    Roy

Maybe you are looking for