php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #37258 lot of missing documentation about oop
Submitted: 2006-05-01 13:17 UTC Modified: 2006-05-01 14:55 UTC
From: php-bugs at T43 dot mine dot nu Assigned: colder (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2006-05-01 13:17 UTC] php-bugs at T43 dot mine dot nu
Description:
------------
the oop5 documentation has a lot of unclear / missing very basic passages. Among them are:

Basics: How to define a member, How to define a method
How to add a member to an instance ($apple->newmember)
How to add a member to the class on the fly
Constructors: the classname($var) syntax

The sentence "Followed by a pair of curly braces, OF which contains the definition " the word 'OF' is grammatically wrong in the ears of non-english, making the sentence non-understandable.

Most of this was missing in the php4 class documentation too. It is not clear whether the php5 class chapter replaces, or augments the php4 class chapter.

I can't fix it as I can't delve into the sources of ZEND engine and the like.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-01 13:29 UTC] php-bugs at T43 dot mine dot nu
more missing. There can only be one constructor, as opposed to C++. So
function classname($var1,$var2) can't coexist with
function classname($var1) .

Further, when there is a constructor, the new operator has to use it.
Given function classname($var1),
the call
$apple= new classname; fails, but
$apple=new classname('apple') is required syntax.
 [2006-05-01 13:40 UTC] php-bugs at T43 dot mine dot nu
The oop5 documentation does not point to the class handling functions (as the oop4 documentation did, on the very first, the 'class' page at the end.)
 [2006-05-01 13:45 UTC] php-bugs at T43 dot mine dot nu
The scope of members, defined on the fly (not in the class definition), is not specified. 

given $this->newmember='sweet', is newmember public?
given $apple->newmember='sour', is newmember public?
 [2006-05-01 13:47 UTC] colder@php.net
1) "How to define a member, How to define a method" 
This is explained in this example:

http://php.net/language.oop5.basic#AEN5708

2) "How to add a member to the class on the fly" 
I fail to see what you're trying to describe here.

3) "Constructors: the classname($var) syntax"
This is already documented:

"For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class."

4) "There can only be one constructor, as opposed to C++."

Who said PHP was like C++? This is how PHP works, you can't define two functions with the same name having different parameters.

5) "Further, when there is a constructor, the new operator has to use it."

This is how functions/methods generally work, if an argument is not optional, you've to specify its value, nothing new/undocumented.

Until you've something new, this bug report seems bogus to me.
 [2006-05-01 14:06 UTC] php-bugs at T43 dot mine dot nu
Thanks for the feedback.

(A) "This is illustrated in the following example: "
but then follow TWO examples, 19-1 and 19-2. English grammar requires
"This is illustrated in the following examples: "

And the examples are a bit meagre. The oop4 documentation was richer.


(B) 2) "How to add a member to the class on the fly" 
I fail to see what you're trying to describe here.

It is allowed to add member fields to just one instance.
given class fruit has no field "sweet", one can add one to an instance, simply by $apple->sweet=true;

(C) >>Until you've something new, this bug report seems bogus to me.
Maybe, but classes, from the manual, have a very steep learning curve, even in php terms.

(D) The reference to the class/object handling functions is missing. From this it is unclear whether oop5 augments, or replaces oop4 documentation.
 [2006-05-01 14:08 UTC] php-bugs at T43 dot mine dot nu
(E) english grammar (as seen by non-english like me) would require the OF removed in the first paragraph.
 [2006-05-01 14:23 UTC] colder@php.net
(A) will be fixed

(B) "It is allowed to add member fields to just one instance."
Even if it's possible, I don't think it's considered as a good practice. I'm not sure if it needs to be explicitely documented, at least I wouldn't recommend it.

(D) will be fixed

(E) will be fixed
 [2006-05-01 14:31 UTC] colder@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2006-05-01 14:40 UTC] php-bugs at T43 dot mine dot nu
May I further suggest for (A), to switch examples 19-1 and 19-2, such that first comes the Simple Example, and then the specialty of $this with respect to static - is nowhere basic and could be easily be referenced from the static section near examples 19-14 and 19-15 ).

regarding (B) there are UCN's that seem to make good use of it for templates.

And an overall "Thank You" for the feedback.
 [2006-05-01 14:55 UTC] php-bugs at T43 dot mine dot nu
I leave it as closed, together with my previous comment.
 [2020-02-07 06:11 UTC] phpdocbot@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=427967c8569300b17e3bfc7a4706de6339cc4262
Log: Fix #37258 (typos + add a reference to class/objects functions)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Oct 08 11:00:01 2025 UTC