473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with classes/constructors

I am rather new at the classes concept in php so maybe I am overseeing
something very simple but anyway I tried the following code:
<?php
class Navbar
{
var $begin = "[";
var $tussen = "][";
var $einde = "]";
function Navbar($bBegin = "[", $bTussen ="][", $bEinde ="]")
{
$this->begin = $bBegin;
$this->tussen = $bTussen;
$this->einde = $bEinde;
}
function openen($item)
{
print $begin.$item;
}
function addItem($item)
{
print $tussen.$item;
}
function sluiten($item)
{
print $tussen.$item.$einde;
}
function test()
{
echo $begin;
}
}
$navBar1 = new Navbar("[","][","]");
$navBar1->openen("Item1");
$navBar1->addItem("Item2");
$navBar1->addItem("Item3");
$navBar1->sluiten("Item4");
$navBar1->test();
?>
The problem is that when I see the page online, the separators (in this case
[ ][ ] ) are not seen. Obviously the variables $begin, $tussen and $einde
are empty.
Any suggestions?

Martien
Jul 17 '05 #1
2 1537
*** Martien van Wanrooij wrote/escribió (Fri, 4 Jun 2004 12:30:56 +0200):
function test()
{
echo $begin;
}


Since $begin is not defined within test() it will be empty. If you are
referring to the class attribute you have to call it this way:

function test()
{
echo $this->begin;
}

You did it fine in constructor.

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #2
Thank you very much Alvaro! This seems to work a little bit different from
Java (as far as I recall anyway) but it is completely clear now.

Martien.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alexander Stippler | last post by:
I've got an inheritance structure with two coupled "dreaded diamonds" like shown below: A / \ / \ B C \ / \ \ / \ D E \ /
3
by: Omer van Kloeten | last post by:
The Top Level Design: The class Base is a factory class with a twist. It uses the Assembly/Type classes to extract all types that inherit from it and add them to the list of types that inherit...
18
by: dover | last post by:
Instantiation of classes is to create objects in areas of memory. As a side effect of that object creation, the constructor is called. Three steps can be identified in an instantiation of a class:...
4
by: Gama Franco | last post by:
Hi, I've been developing this API, but now I get stuck in a compiling error and I'm out of ideas. Some comments are welcome. The hierarchy is bases in three classes, and I will explain it...
24
by: Alf P. Steinbach | last post by:
The eighth chapter (chapter 2.1) of my attempted Correct C++ tutorial is now available, although for now only in Word format -- comments welcome! Use the free & system-independent Open Office...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
3
by: Ross McLean | last post by:
Hi all, I've been teaching myself C# for a new project at work. I have a bit of a background in c++ and java but never been what you could call a guru. I'm having some strange things happening...
1
by: PeterG | last post by:
Hi, I am relatively new to Python, and am learning it as part of a university module... Im currently undertaking a project to create an IM server and IM gui client. I have a very basic...
5
by: tobias.sturn | last post by:
Hi! I have written this template for making a singleton: #define DECLARE_SINGLETON(classname) \ private: \ static classname* m_pThis; \ classname(); \ class Guard \ { \ public: \
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.