Jump to content

classes$function


fluteofliar

Recommended Posts

In php,AFAIK dollarsign($) is part of variable thatswhy we always variable

using this sign........

Now,whats wrong when i use the above defination while accessing a member variable of a class using object, for instance

<?php

class hello

{

public $a="php seems sometime illogical";

function _construct()

{

echo "howz your php experience?";

}

}

$obj=new hello();

$obj->a;//this works fine

$ob->$a;//error::can,t acess empty property?

 

2)does function are define at the point they call in php?

why its necessary to call inner function first before outer function in nested function

Link to comment
Share on other sites

In that context $a has no value. So you're trying to access a property with a null name, which obviously doesn't exist. You could however do this:

 

$a = 'a';
$ob->$a;

 

When calling the property of a class you just don't use the dollar sign in front of the variable name, that's just how it is.

Link to comment
Share on other sites

In that context $a has no value. So you're trying to access a property with a null name, which obviously doesn't exist. You could however do this:

$a has value but while accessing it like

obj->$a ... it means we are trying to acess the property of object which is refer as $$a inside the object

but the property $($a) is empty....well thankz mate for taking pain to reply my quest :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.