php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #11142 '::' for object variables. Static code
Submitted: 2001-05-27 14:39 UTC Modified: 2002-01-28 20:49 UTC
From: foobardotcom at poczta dot onet dot pl Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.5 OS: all
Private report: No CVE-ID: None
 [2001-05-27 14:39 UTC] foobardotcom at poczta dot onet dot pl
I just want, you make this code possible:

<?php
  class foo {
    var $bar = "dot";
  }
  echo foo::bar;
?>

============================================================

Second request is about static code part in class declaration. It is because 'var' statement doesn't support function results. There is way for omit this problem -- do it using constructor.
There is one problem. If I want to use it by '::' operator, I must use constructor before using this class... and there are so many problems with it.

My proposition is that:

<?php
  class foo {
    static {
      $conn = pg_connect("dbname=example");
    }
    function getConnection() {
      return $this->conn;
    }
  }
  $globalConn = foo::getConnection();
  // ...
?>

Meaning of that is just request for operations on classes, not on instances only.
Static part of class declaration is very usefull. In that code you can e.g. place other constructions -- for() or while().

I believe in you!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-28 20:49 UTC] yohgaki@php.net
Will be in ZE2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC